Skip to main content

Drupal deployment using drush

Category: Drupal 8
drupal-logo

By using drush you can easily sync content of 2 drupal installations. This is a short introduction.

Requirements

  • drush needs to be installed on both hosts
  • it is recommended that you access the remote host via ssh by using your ssh-key which is authorized on remote (.ssh/authorized_keys

First we need to define the existing instances by adding the following content to aliases.drushrc.php (at ~/.drush/). 

<?php

$aliases['dev'] = array(
 'root' => '/var/www/drupal',
 'uri' => 'localhost/drupal',
 'path-aliases' => array(
    '%dump-dir' => $local_sites . 'drush.dbdumps',
    '%files' => $local_sites . 'sites/default/files',
    '%themes' => $local_sites . 'themes'
 )
);

$aliases['live'] = array(
   'root' => '/var/www/drupal',
   'uri' => 'example.com',
   'remote-host' => '80.80.80.80',
   'remote-user' => 'root',
   'path-aliases' => array(
     '%dump-dir' => $local_sites . 'drush.dbdumps',
     '%files' => $local_sites . 'sites/default/files',
     '%themes' => $local_sites . 'themes'
   ),
    'databases' => array (
      'default' =>
      array (
        'default' =>
        array (
          'database' => 'databse',
          'username' => 'user',
          'password' => 'password',
          'host' => 'localhost',
          'port' => '',
          'driver' => 'mysql',
          'prefix' => '',
        ),
      ),
    ),
 );

For copying the files to the remote host we simply run the following command:

drush core-rsync @dev @live

By default config files will not be synced. For syncing those just add option --include-conf.

Later on we should sync the other folders, e.g. uploaded files:

drush rsync @dev:%files/ @live:%files

Finally we need to sync the databse. The connection data can be defined at settings.php, aliases.drushrc.php or as option for sql-sync-command.

drush sql-sync @dev @live