The TYPO3 console is a great tool in order to get things done quickly. It provides many commands that will ease your live with TYPO3 a lot. Even if you are not used to command line tools, you should, no, you must have a look at this post. ;-)
TYPO3 Console: A CLI tool for TYPO3
Basically the TYPO3 Console enables you to run tasks which are doing “something” with your TYPO3 installation. Usually these are tasks that require several mouse clicks in the backend. Now they are available via your keyboard.
But first, let me add a small paragraph about “CLI phobia”.
Don’t be scared of the command line!
Probably you would say now: “Hmm, I’m a windows guy and do not have any experience using the command line. So that is nothing for me!”.
Sorry, this is completely wrong. The command line does not bite. The learning curve is not steep. So you will have success from the first moment.
And please do not conclude from a MS-DOS window to “modern shells”. The tools nowadays are much better usable than these ancient tools.
Installation and basic usage of the TYPO3 console
The installation of the TYPO3 console is quite easy. You can install it via the “Extension Manager” in the TYPO3 backend. Search the TER for “typo3_console” and install it as any other extension. After the installation, the script will be symlinked to your document root.
The second possibility is to install it via composer. A quick composer require helhum/typo3-console
is sufficient. Afterwards you can access the tool (usually) in the path /vendor/bin/
below the file “composer.json”
Basic Usage
The script is named typo3cms
. In order to see whether it is working, you should login to your website instance and call typo3cms help
from the document root (in case of the installation via the Extension Manager) or ./vendor/bin/typo3cms help
from your website root (in case you installed it via composer).
Now you should see the list of all available commands of the TYPO3 console.
If there is an php error, you must check the php version, which is provided on your command line. The necessary command is php --version
. This must be equal to the version your TYPO3 instance is running. If the version number is too low, you need to add the path to the correct php binary right in front. In case of a big german hoster, whose default php version on the command line is 4.4.9, the complete command looks like:
/usr/local/bin/php7-70LATEST-CLI vendor/bin/typo3cms help
Available Commands
The following sections will give you an introduction to the most commands of this tool.
Database operations
The database
command provides three subcommands: updateschema
, export
and import
.
How often do you look up the database access credentials in order to import or export to or from a database dump? With the command typo3cms database:export > /path/to/your/dump
this is not necessary any more … The TYPO3_console fetches the credentials automatically and runs the mysql
and mysqldump
command transparently.
The subcommand updateschema
is equivalent to the “Database compare” in the InstallTool. Per default the command only adds fields and tables and changes column definition. You can specify, which operations should be performed.
Clearing the cache
Cache operations are probably the most executed task in the TYPO3 backend (#scnr). This command group allows you to clear caches via command line. Several option to define the caches to be cleared are available. You can restrict cache clearing certain cache groups, like pages or system. You can also limit the flushing to certain cachetags, you used in the system.
Examples are typo3cms cache:flushtags news_pressreleases
or typo3cms cache:flush
Extension operations
This group deals with extension handling and performs tasks like setting up and removing extensions. You can setup a single extension with the command typo3cms extension:setup <my-extensionkey>
. This command executes all database migrations, imports all files and data and writes the default configuration. The subcommand extension:setupactive
does this for all activated
Furthermore you can (de-)activate extensions, dump autoload data and list all available extensions.
Working with configuration
The command configuration
allows to read, set and remove values of, in and from the array $GLOBALS['TYPO3_CONF_VARS']
.
➜ t3trunk ./vendor/bin/typo3cms configuration:show MAIL [ [ 'transport' => 'mail', 'transport_smtp_server' => 'localhost:25', 'transport_smtp_encrypt' => '', 'transport_smtp_username' => '', 'transport_smtp_password' => '', 'transport_sendmail_command' => '/usr/sbin/sendmail -t -i ', 'transport_mbox_file' => '', 'defaultMailFromAddress' => '', 'defaultMailFromName' => '', ], ]
Nested parts can be referenced in a usual path notation, as you can see in the example below.
➜ t3trunk ./vendor/bin/typo3cms configuration:show MAIL/transport [ 'mail', ]
Installation actions
The command install:setup
allows you to install a complete TYPO3 instance via the command line. You may not run the graphical “1-2-3-4-x”-Wizard any more. Especially if you want a quick setup of an instance for testing purposes. A setup of TYPO3 including the introduction package is done in less than ten minutes.
The other two subcommands of setup
are fixfolderstructure
and generatepackagestates
. Their purpose is quite self-explaining.
Upgrading TYPO3
Since the release 4.5.0 the TYPO_console allows you to run the available upgrade wizards. There is no need to do the click maranthon in the InstallTool any more.
The subcommand list
lists all upgrade wizard, that are scheduled for execution. Using the subcommand all
you can run all upgrade wizards, which are not done yet. If you want run just a specific wizard, the subcommand wizard
is your friend.
Other commands
There are several more commands available for tasks like updating language files, generating a xsd file for fluid viewhelpers, running a certain scheduler task or locking backend access for editors and admins.
For a complete list and explanation you should definitly have a look at the current command reference on github.
If you think RTFM is too boring for you, the autocompletion might a thing for you.
Autocompletion
Currently there are 36 (sub-)commands available via the TYPO3 console. Not counted all the properly registered command controllers in TYPO3 extensions like “EXT:Powermail” or “EXT:metaseo”. This is all hard to remember.
But the TYPO3_console brings a command which is able to generate an autocompletion file for zsh and bash. Here is the snippet, I used to create the file:
./vendor/bin/typo3cms autocomplete --shell=zsh > /.typo3cms_completion
echo "source /.typo3cms\_completion" >> /.zshrc
If you are using bash, you must adapt the zsh stuff to your needs and make sure that bash is able to cope with autocompletion. More details and links are available in the documentation of the TYPO3_console.
Creating additional commands
Good news! Not each and every command has to be implemented into the core of the TYPO3_console! The TYPO3_console provides access to every extbase command controller, which is properly registered within TYPO3.
So if you want to add functionality to the TYPO3_console, just create an extension containing command controllers. I recommend to choose a meaningful prefix for your command class. Something like “TaskCommandController” is not helpful, because all extensions, using it, will summed up there. This is different to the old “cli_dispatch.sh”, where the tasks were prefixed by the extension key.
Conclusion
First of all I want to thank Helmut Hummel for his dedication to the TYPO3 Console and the TYPO3 project as a whole. I really appreciate his commitment. If you think the same, get in contact with him and sponsor the next steps … or just do him some kind of favor … or just say thank you :-)
I hope, that this post has been interesting for you. If so or if you know somebody, who could profit from it, please share this post via your favorite social network. For your convenience I added some share buttons at the end of this page.
I found the blog post image on pixabay . It was published by StartupStockPhotos under the CC0 public domain license. It was modified by myself using pablo on buffer.
TYPO3-Console in my eyes is on of the top 3 extensions for TYPO3. To be honnest, its my #1. I am not really willing to think about not having it. It makes a lot of things really easy. I hate working in (older) projects where there is no console! So even if you dont want to use it locally, use it while deploying to ur server!
Great work @helhum!
Hi, thanks for this Post :thumbs-ub:
But could it be there is a typo in rhe EXT:Key?
> Search the TER for “typo3_cms”
Yes, there is a typo. Thanks! … and I will fix it now
Pingback: Links der Woche… - TYPO3 Blogger | TYPO3 Blogger
I’m currently setting up a
composer.json for a development TYPO3 system and I’m not able to install TYPO3-Console/typo3_console.
Isn’t helhum/typo3-console the right package to require?
(https://github.com/TYPO3-Console/typo3_console#installation-using-composer)
Thanks a for the article and thanks to @helhum!
Is there any error message you get? Which versions (TYPO3 / php)do you use?
I have the same issue as Christian. I get the following error:
InvalidArgumentException
Could not find package TYPO3-Console/typo3_console at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
And also no results on packagist.org
https://packagist.org/search/?q=typo3_console
Pingback: TYPO3 Extension Roundup Q1 + Q2 - 2017 | TYPO3worx - "The" TYPO3 Blog
I get always the message
typo3cms: command not found
. Instead I have to writephp ./vendor/bin/typo3cms
. How can I access the shortformtypo3cms
?You will need at last the form “./vendor/bin/typo3cms”, because the command does not reside somewhere in your PATH-variable.
Whether you need the “php” part depends on your system. You only need this, if there is no php binary somewhere in your $PATH. TYPO3console takes the first one of your PATH … by adding “/php”, you can overwrite this.
This is useful, if the first php binary in $PATH is from php 5.6, but you want to use php 7.0 for example.
Hallo Marcus,
sehr schön geschriebener Artikel.
Vielen Dank für Deine Mühen! :D
Ich versuche mir auch gerade eine Composer Installation zu bauen, die so viel automatisch erledigt, wie möglich.
Wenn ich z.B. diesen Befehl ausführe:
bash ./vendor/bin/typo3cms extension:setup --typo3-ter/realurl
Kommt als nächstes noch mal die Frage
$ bash ./vendor/bin/typo3cms extension:setup –typo3-ter/realurl
Please specify the required argument "--extension-keys":
Kommt diese Fehlermeldung:
[ TYPO3\CMS\Core\Package\Exception\UnknownPackageException ]
#1166546734: Package "typo3-ter/realurl" is not available. Please check if the package exists and that the package key is correct (package keys are case sensitive).
thrown in file D:\projekt\vendor\typo3\cms\typo3\sysext\core\Classes\Package\PackageManager.php
in line 504
Gebe ich hier den extension-key falsch an?
Vielen Dank und Gruß
Torsten
Ich denke, ich habe meinen Fehler gefunden.
Ich musste vorher install:generatepackagestates ausführen.
Das hat dann geholfen. :)
5