Deploy Sulu with Deployer

Deployer is a cli tool for deployment of any PHP applications, including frameworks such as Laravel, Symfony, Zend Framework and many more. Main concept of Deployer is recipe, a php file containing tasks definitions. Also Deployer comes with bunch of ready to use recipes from community for Slack, etc.

Features

  • Simple setup process and a minimal learning curve
  • Ready to use recipes for most frameworks
  • Parallel execution without extensions
  • Something went wrong? Rollback to the previous release
  • Agentless, it’s just SSH
  • Zero downtime deployments

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 1.x (based on Symfony 2.8 installation) recipe as the basic configuration.

<?php

namespace Deployer;

require_once __DIR__ . '/vendor/deployer/deployer/recipe/symfony.php';

add('shared_dirs', ['public_html/images', 'public_html/uploads', 'uploads']);
add('shared_files', ['app/config/parameters.yml']);
add('writable_dirs', ['app/cache', 'app/logs', 'uploads', 'public_html/uploads']);

set('writable_mode', 'chmod');

set('app/console', function () {
    return parse('{{bin/php}} {{release_path}}/app/console --no-interaction');
});

desc('Migrate PHPCR');
task(
    'phpcr:migrate',
    function () {
        run('{{bin/php}} {{app/console}} phpcr:migrations:migrate {{console_options}}');
    }
);

desc('Clear cache');
task('deploy:website:cache:clear', function () {
    run('{{app/console}} cache:clear {{console_options}} --no-warmup');
});

desc('Warm up cache');
task('deploy:website:cache:warmup', function () {
    run('{{app/console}} cache:warmup {{console_options}}');
});

after('deploy:cache:clear', 'deploy:website:cache:clear');
after('deploy:website:cache:clear', 'deploy:website:cache:warmup');

host('dev')
    ->hostname('demo.host.lt')
    ->port(22)
    ->user('demo')
    ->forwardAgent()
    ->stage('dev')
    ->set('branch', 'master')
    ->set('deploy_path', '/home/demo/domains/host.lt');

set('dump_assets', false);
set('http_user', 'demo');
set('repository', '[email protected]:demo/host.git');

set('clear_paths', [
    'app/cache'
]);

// 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

When you deploy for the first time, create your VirtualHost based on the webserver you use. As Deployer uses symlinks, the webserver should be allowed to follow symlinks and the VirtualHost 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.

Source: Sulu Blog

Leave a Reply

Your email address will not be published. Required fields are marked *