Information for: DEVELOPERS   PARTNERS

Drush and Drupal 7 on Cloud Platform

This page is for Drupal 7 only. For information about Drush and Drupal 8, see About Drush on Cloud Platform.

Drush is a command-line shell for Drupal, and it enables you to perform many administrative and application maintenance tasks from the command line instead of Drupal’s administrative interface.

Unless you are using Live Development, Drush cannot write to the Cloud Platform file system, so you cannot use it to manage your application’s code, or install or update modules. To manage your code, use your version control system, Git. As an alternative, you can enable the Live Development feature. With Live Development enabled, you can log into your Cloud Platform server and use Drush or other tools to write to the file system. You can use Live Development to modify only your Dev and Stage environments, not your Prod environment. For more information about Live Development, see Using Live development mode to change code on your server. A more powerful and flexible alternative is to develop locally and use Acquia Dev Desktop to sync your code between your local environment and Cloud Platform. Acquia Dev Desktop provides full support for Drush.

Developing locally with Drush and Drupal 7

The fastest and easiest way to work with your application is to develop it on your local computer, rather than attempting to manage code or modules remotely on Cloud Platform. You can change your application’s code, use Drush locally to add or update modules, and then send the changes to Cloud Platform using your selected source control method (Git) or using Acquia Dev Desktop (download).

You can use Drush on Cloud Platform to help you develop locally. For example, suppose you want to be able to locally access your development environment database. To be able to access the database locally, enable SSH, securely connect to Cloud Platform, and then run the following Drush command, replacing [env] with your environment name, and [site] with your subscription’s sitename:

Note

Drush commands should generally be run from your website’s docroot.

drush @[site].[env] ah-sql-connect --env=[env] --site=[site]

The command provides the MySQL connection settings required to access the database. Replace [site] with your application’s name and dev with the environment whose database you want to reach. You can then provide these settings to a MySQL client installed on your computer (such as MySQL Workbench or Navicat). If your subscription is a single-tier subscription, you can access your development environment’s database from your local computer after you configure the MySQL client to connect to the database server using an SSH tunnel.

Remote development - Drush resources on Cloud Platform

Drush is pre-installed on Cloud Platform, and you can use Drush with your applications after you enable SSH access to connect to Cloud Platform using SSH.

The Cloud Platform API is a RESTful web interface that allows developers to extend, enhance, and customize Cloud Platform. It includes Drush commands that allow you to use all features of the Cloud API.

Using different versions of Drush on Drupal 7

Cloud Platform can run most stable versions of Drush, from Drush 9 to Drush 5. Drush 8 is the default, recommended version.

Important

  • Cloud Platform defaults to the currently installed version of Drush 8.
  • Drush 9 and Drush 10 aren’t supported with Drupal 7.

To run a specific version of Drush, specify the major version in the drush command. For example, to run Drush 7, use the command drush7. To run the default version of Drush, use the command drush. On Cloud Platform, the default version of Drush is currently Drush 8.

Note

  • Drush 8 is the only fully supported version of Drush for Cloud Platform for Drupal releases prior to Drupal 8.5.
  • Acquia strongly recommends that you always run a specific major version of Drush. Running the default version of Drush is dangerous because the behavior of your cron jobs, Cloud Hooks, or other automated scripts may change unexpectedly when a new version of Drush becomes the default.

If you want to change your personal default Drush version, you can set an alias for drush in a .bashrc file. For example, to make the drush command run Drush 7, add this to your ~/.bashrc file:

alias drush=drush7

This alias will work only for interactive SSH commands; it will have no effect during cron jobs or Cloud Hooks. To use a specific version of Drush in a cron command, you must call it directly, as follows:

/usr/local/bin/drush7

When you run Drush on your local computer and use a remote Drush alias for your Cloud Platform application (such as those described in Using Drush aliases), the remote Drush command will be run using the default version of Drush on Cloud Platform. To run a specific version of Drush on Cloud Platform when you use a remote alias, edit the alias file in the $HOME/.drush folder on your local computer to specify the version you want. For example:

$aliases['dev'] = array(
  'path-aliases' => array(
    '%drush-script' => 'drush7',
  ),
  // ... other alias settings here
);

Accessing environment databases

Each of an application’s environments on Cloud Platform has its own database, and when you use Drush to access these databases, you must refer to them

specifically. For example, if you want to use drush sql-connect for the database in the development environment of your application, use the following command, replacing [env] with your environment name, and [site] with your subscription’s sitename:

drush @[site].[env] ah-sql-connect --env=[env] --site=[site]

Finding help for Drush

To access help for Drush online, go to Drush Commands.

To access command-line help, enter drush help on the command line while you are signed in to your Cloud Platform server. For a printable version of this list, enter the following command: drush help --html.