Matomo can be used through several interfaces, the command line being one of them.
The CLI console enables users to run commands defined by plugins. The commands can be used to perform maintenance, to monitor the application, to ease development, and so on.
To use Matomo on the command line, all you need to do is run the console tool. The tool is a script located in Matomo's root directory and called
console. You can run it with the command:
php ./console help
The Matomo console is built using the Symfony Console component. If you are familiar with Symfony, it should be easy to find your way in the Matomo console.
The console can be used to run Matomo commands like so:
The console comes with many commands, for example to generate empty plugins and plugin files with, run git commands, watch Matomo's log output, run tests, and deal with Matomo translations.
You can view the entire list of commands by running the following command:
To get more information about a single command (such as its arguments), run the following command:
./console help <command>
<command> should be replaced with the command you are interested in.
Plugins can extend the command line tool by creating their own commands. To do so you can use the CLI itself:
./console generate:command --pluginname=MyPlugin
This will create a folder named
Commands within your plugin along with a PHP file which represents the actual command. You can add an unlimited number of commands to a plugin.
To learn how to flesh out your command, you can read the Symfony Console documentation.
Nevertheless, there are some differences when building Matomo commands. As plugins should avoid any direct references to Matomo's dependencies we have our own Command class to inherit from.
This class inherits from the Symfony Console Command class, but has some adjustments that will avoid the direct requirement of using typehints like
OutputInterface, class constants from
InputArgument and any Console helpers.
* Methods like
initialize cannot be overwritten. Instead, use our custom methods prefixed with
* Wherever you need to work with input or output, use
$this->getOutput() instead. Don't use
OutputInterface as method typehints.
* When configuring input options and arguments
addArgument cannot be used
* For arguments use
* For options use
* Directly using any of the console helpers is now prohibited
* To get user's input use the new methods
* For progress bars use the methods
* To render tables use the new method
* For executing another command within your command use the method