Deploy Sulu with Deployer

Deployer is a well known deployment tool for PHP applications and we are happy to announce that the new version of Deployer is shipped with recipes for Sulu. Once configured, it's easy to deploy your application on one or multiple webservers.

Installation of Deployer

To use Deployer we first need to install it as dependency over composer.

composer require deployer/deployer --dev

Configure Deployer

To configure the deployment you need to create a deploy.php in your application.

Since version 6.4, Deployer is shipped with two recipes for Sulu. One for Sulu 1.x, based on the sulu-minimal repository, and Symfony 3 and one for Sulu 2.x, based on Symfony 4. In the following example we will use the newer Sulu 2.x recipe as the basic configuration.

<?php

namespace Deployer;

require 'vendor/deployer/deployer/recipe/sulu2.php';

host('sulu.io')
    ->user('hikaru')
    ->set('deploy_path', '/var/website/sulu.io')
    ->set('branch', function () {
        return input()->getOption('branch') ?: 'master';
    })
    ->set('http_user', 'www-data')
    ->set('http_group', 'www-data')
    ->stage('prod');

// Configuration
set('repository', 'git@github.com:website/sulu-website.git');

set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --apcu-autoloader');

// Optional Scripts when using migrations:
// before('deploy:symlink', 'database:migrate');
// before('deploy:symlink', 'phpcr:migrate');

// if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

Deploy the application

To deploy your application you just need to run the following command:

bin/dep deploy prod
Deploy output of the sulu website Deploy output of the sulu website

When you deploy for the first time, create your VHost based on the webserver you use. As Deployer uses symlinks, the webserver should be allowed to follow symlinks and the VHost should always point the the current directory of the deployed application.

Deployer has many configuration options for connections, permissions etc. and recipes which can be found in the documentation.

There are also some additional recipes in the deployer/recipes repository, e.g. one to clear opcache.

Once Deployer is configured correctly for your server, you can easily deploy your Sulu website or application using continous deployment over continous integration server.

Give it a try and let us know if the Deployer recipes for Sulu works correctly for you.