Skip to main content

Deploying Sulu CMS with Deployer

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

For traditional non container deployments, Deployer is a value tool to simplify & automate the deployment process of a PHP application. Thanks to its collection of default deployment recipes, Deployer can be used out-of-the-box for deployments.

One of the many out-of-the-box recipes offers a default deployment workflow for Sulu CMS. To use the recipe, create a deploy.php file in your project repository with the following contents:


namespace Deployer;

require 'recipe/sulu.php';

// Configure project name and Git repository
set('application', 'My Sulu website');
set('repository', '');

// import the hosts configuration

In the hosts.yaml file, you define all hosts to deploy the application to:

deploy_path: /var/www/html/
remote_user: sulu-user

This allows you in your deployment pipeline to run a deployment by calling Deployer like this

./bin/dep deploy --file ./deploy.php

The downside of the command above is that it will always deploy the latest master branch state, which is not ideal for reproducible deployments. Luckily, Deployer has a solution for that, by passing the --tag argument, we can specify the git tag that should be used for the checkout:

./bin/dep deploy --file ./deploy.php -tag "1.2.3"

And the best thing about Deployer is its flexibility. For a standard Sulu setup, the Sulu recipe works fine. Since we are using the Sulu Headless Bundle for our projects, we have not only to deploy/compile the Sulu "backend" but also the React frontend.

This can be done by adding another task like this:

task('deploy:headless:deploy', function () {
run('cd {{release_path}}/assets/headless && yarn && yarn build');

after('deploy:prepare', 'deploy:headless:deploy');

Or if you prefer to compile the frontend in your CI environment and just upload the build frontend, the following deployment snippet will do:

task('deploy:headless:deploy', function () {
upload('public/build/headless', '{{release_path}}/public/build');

after('deploy:prepare', 'deploy:headless:deploy');

As you can see, using Deployer is not too complicated, thanks to recipes that come with Deployer out-of-the-box. Thanks to its flexibility, you can adjust all the bolts as needed. For example, if you are using Tideways for application performance monitoring, you can use Deployer to trigger a Tideways Deployment event for the Tideways reports.