Search code examples
phpdrupaldrush

Updating remote site with drush and ssh


I'm very new to drush. We have a git repo of a drupal site that I would like to push to the remote server using drush. I can easily scp the drupal files or setup a cron on the remote that runs git pull but I still would like to learn how to push code and sync a remote drupal site with my local drupal.

Currently, I have drupal running locally and I use git to update the repo. The ssh is already configured and I can ssh to the remote drupal server using keys. I have also created .drush/aliases.drushrc.php file and I tested it by running drush @dev status. It worked well

<?php

    $aliases['dev'] = array(
        'root' => '/var/www/html',
        'uri' => 'dev.example.com',
        'remote-host' => '192.168.1.50'
    );

?>

Now, I would like my local drupal site to be synchronized with our server on 192.168.1.50 server. The local drupal files are on my /home/ubuntu/drupal_site.

I have few questions:

  1. What is the drush command/parameters to update remote drupal server?

  2. What will be the drush command/parameters if remote server doesn't have drupal files yet?


Solution

  • Backup before synchronizing with drush ard or drush @dev ard or with the suited alias. You can set the backup path in the alias settings.

    I think you named your remote server dev. That is why I keep this in the following and use the alias local for the local drupal site.

    Add the alias for your local drupal site. Then you can use the following command to synchronize the files:

    drush rsync @local @dev
    

    There @local is the source and @dev the target. More details on how to use the command rsync can be displayed with:

    drush help rsync
    

    You also need to synchronize the database to get the remote site running. For this add the database account data to the alias data for @local and @dev. It will look something like this:

    'databases' => array(
      'default' => array(
        'default' => array(
          'driver' => 'mysql',
          'username' => 'USERNAME',
          'password' => 'PASSWORD',
          'port' => '',
          'host' => 'localhost',
          'database' => 'DATABASE',
        )
      )
    )
    

    Replace the space holders with your data. Then databases can be synchronized with:

    drush sql-sync @local @dev
    

    There @local is the source and @dev the target.


    Initially the synchronization will happen in one direction. After this it is good practice to synchronize files from development or test site to the productive site. The database is synchronized the other way around from productive site to development or test site.