Commands

Contao uses the Console component of Symfony and provides a few commands. To execute these commands locate the console executable in your project and append the subsequently documented commands.

$> php bin/console <command-name>

In the Contao Managed Edition, the path to the console script is vendor/bin/contao-console instead.

By appending the --help argument to any command, a usage guide is printed to the shell.

$> php bin/console contao:user:password --help

Description:
  Changes the password of a Contao back end user.

Usage:
  contao:user:password [options] [--] <username>

Arguments:
  username                 The username of the back end user

Options:
  -p, --password=PASSWORD  The new password
  []

contao:automator

This command is an interface to the Automator class of Contao. It mainly consists of common tasks around the maintenance of a Contao installation.

$> php bin/console contao:automator [<task>]

The command itself can be executed without providing a task. It will then ask for it. The following tasks are available.

Task Description
purgeSearchTables Clears the search index by deleting the tables tl_search and tl_search_index.
purgeUndoTable Removes the temporarily stored undo entries, which allows for restoring deleted entries.
purgeVersionTable Purges the version table tl_version which holds different versions for rows in tables that have the versioning feature enabled.
purgeSystemLog Deletes entries in the system log.
purgeImageCache Purges the image cache by deleting all processed and resized images in the configurable image.target_dir.
purgeScriptCache Removes processed and/or minified JavaScript files and Stylesheets.
purgePageCache Clears the page cache by removing cached html responses.
purgeSearchCache Clears the search result cache.
purgeInternalCache Clears the internal cache directory in kernel.cache_dir, this includes the Symfony application cache and potentially hits non Contao caches.
purgeTempFolder Purges the complete temporary folder.
purgeRegistrations Purged the unactivated member registrations.
purgeOptInTokens Purged the expired double opt-in tokens.
purgeXmlFiles Removes xml files generated by generateXmlFiles task.
generateSitemap Generates the sitemap.xml files based on the page tree and the settings on the root page.
generateXmlFiles Generates the sitemap.xml files and calls the hook generateXmlFiles for other bundles to use. The ContaoNewsBundle uses it to generate RSS feeds.
generateSymlinks Creates various symlinks to the web directory, for example publicly reachable file directories, the assets directory or system/themes.
generateInternalCache Warms up the internal cache.

contao:crawl

This feature is only available in Contao 4.9 and later.

As of Contao 4.9, Contao is equipped with an HTTP crawler. Internally, it is built on top of Escargot. The crawler essentially just crawls all the URLs generated by Contao as any other crawler. It follows links that are part of the sitemap.xml, respects robots.txt information, the rel attribute on links and much more. While doing this, any number of so-called “subscribers” can subscribe to the results of the HTTP requests and basically process them further in any way they want. As of today, Contao knows two subscribers:

  • search-index - updates the built-in search index (only available if searching was even enabled)
  • broken-link-checker - checks all the pages for broken links

Any extension might provide additional subscribers so this list is not necessarily conclusive. Use it as follows:

$> php bin/console contao:crawl [options] [<job>]

There is only one argument to this command which is job. It is optional and represents a job ID. Crawling can be a very long-running task so in case you want to stop and pick up where you left later, you need to remember the job ID you were assigned when you first ran the command and you can then resume with that job ID later on. However, as there is usually no such thing as memory or runtime limits on CLI, this will likely not be used very often.

The options are far more important so let’s get to them right away:

Option Description
--subscribers (-s) By default, all subscribers are enabled but you can pass a comma-separated list of subscribers you want to enable. E.g. if you only want to check for broken links, only pass broken-link-checker here.
--concurrency (-c) This option allows to configure the number of concurrent requests. The higher, the faster the process will complete but webservers only handle a certain amount of concurrent requests so choose the value wisely.
--delay To make sure you are not hammering a webserver, you can also configure a delay. This is in microseconds and will just cause the crawler to wait n microseconds between requests.
--max-requests By default, there is no limit configured but if you want to only execute a certain number of requests in total, you can do that with this option. If you want to pick up the job later, see the job argument.
--max-depth This is the tree depth, the crawler is going to search. The root page is basically level 1 and all the links found there will be level 2. All the links found on level 2 will be level 3 and so on. By default, there is no max-depth configured. The higher the number, the deeper the crawler will search but it will also take longer.
--enable-debug-csv By default the subscriber results are written to the standard output. You can ask the command to write everything to a CSV file by passing this option.
--debug-csv-path This option allows you to override the default CSV file path, if you used --enable-debug-csv.

contao:migrate

This feature is only available in Contao 4.9 and later.

With this command you can execute migrations after an update of Contao or of an extension. The migrations that get executed are update scripts of Contao, registered migrations of extensions, legacy runonce.php files and the database update.

$> php bin/console contao:migrate [options]
Option Description
--with-deletes Executes all database migrations including DROP queries.
--schema-only Executes database schema migration only. Update scripts, registered migrations and runonce.php files get skipped.
--no-interaction With this option enabled all confirmation questions are automatically answered with “yes”. This is useful if you want to execute the migrations in an automated system.

contao:resize-images

This feature is only available in Contao 4.8 and later.

With this command you can process all deferred images that were not yet resized.

$> php bin/console contao:resize-images [options]
Option Description
--concurrent Run multiple processes concurrently with a value larger than 1 or pause between resizes to limit CPU utilization with values lower than 1.0. On a shared hosting environment it might make sense to use a value lower than 0.5 to limit the CPU consumption to 50%.
--time-limit Time limit in seconds after which the command should stop execution.
--image=IMAGE Pass an image path like 1/foobar-f6eac395d.jpg (without the assets/images prefix) to resize one specific image only.
--no-sub-process Disables the use of a sub process for each image resize. Use with caution, this could result in an extremely high memory consumption.

Other commands

  • contao:filesync: Synchronises the file system to the database.
  • contao:install: Creates various empty directories which Contao relies on.
  • contao:symlinks: Creates various symlinks to the web directory, for example publicly reachable file directories, the assets directory or system/themes.
  • contao:user:password: Allows for changing a users password on the shell.