How to Deploy a Contao Project
require 'recipe/contao.php';
Deployer is a free and open source deployment tool written in PHP. It helps you to deploy your Contao application to a server. It is very easy to use and has a lot of features.
Three main features of Deployer are:
- Provisioning - provision your server for you.
- Zero downtime deployment - deploy your application without a downtime.
- Rollbacks - rollback your application to a previous version, if something goes wrong.
Additionally, Deployer has a lot of other features, like:
- Easy to use - Deployer is very easy to use. It has a simple and intuitive syntax.
- Fast - Deployer is very fast. It uses parallel connections to deploy your application.
- Secure - Deployer uses SSH to connect to your server.
- Supports all major PHP frameworks - Deployer supports all major PHP frameworks.
You can read more about Deployer in Getting Started.
The deploy task of Contao consists of:
- deploy:prepare – Prepares a new release
- deploy:info – Displays info about deployment
- deploy:setup – Prepares host for deploy
- deploy:lock – Locks deploy
- deploy:release – Prepares release
- deploy:update_code – Updates code
- deploy:env – Configure .env file
- deploy:shared – Creates symlinks for shared files and dirs
- deploy:writable – Makes writable dirs
- deploy:vendors – Installs vendors
- contao:maintenance:enable – Enable maintenance mode
- contao:migrate – Run Contao migrations
- contao:maintenance:disable – Disable maintenance mode
- deploy:publish – Publishes the release
- deploy:symlink – Creates symlink to release
- deploy:unlock – Unlocks deploy
- deploy:cleanup – Cleanup old releases
- deploy:success – Deploys your project
The contao recipe is based on the symfony recipe.
Configuration
public_path
Overrides public_path from recipe/provision/website.php
.
The public path is the path to be set as DocumentRoot and is defined in the composer.json
of the project
but defaults to public
from Contao 5.0 on.
This path is relative from the current_path, see recipe/provision/website.php
.
$composerConfig = json_decode(file_get_contents('./composer.json'), true, 512, JSON_THROW_ON_ERROR);
return $composerConfig['extra']['public-dir'] ?? 'public';
bin/console
Overrides bin/console from recipe/symfony.php
.
return '{{bin/php}} {{release_or_current_path}}/vendor/bin/contao-console';
contao_version
$result = run('{{bin/console}} --version');
preg_match_all('/(\d+\.?)+/', $result, $matches);
return $matches[0][0] ?? 'n/a';
symfony_version
Overrides symfony_version from recipe/symfony.php
.
$result = run('{{bin/console}} about');
preg_match_all('/(\d+\.?)+/', $result, $matches);
return $matches[0][0] ?? 5.0;
Tasks
contao:migrate
Run Contao migrations.
This task updates the database. A database backup is saved automatically as a default.
To automatically drop the obsolete database structures, you can override the task as follows:
task('contao:migrate', function () {
run('{{bin/php}} {{bin/console}} contao:migrate --with-deletes {{console_options}}');
});
contao:manager:download
Download the Contao Manager.
Downloads the contao-manager.phar.php
into the public path.
contao:install:lock
Lock the Contao Install Tool.
Locks the Contao install tool which is useful if you don't use it.
contao:manager:lock
Lock the Contao Manager.
Locks the Contao Manager which is useful if you only need the API of the Manager rather than the UI.
contao:maintenance:enable
Enable maintenance mode.
contao:maintenance:disable
Disable maintenance mode.
deploy
Deploy the project.
This task is group task which contains next tasks: