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 infrastructure 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 infrastructure.
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).
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:
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 infrastructure 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.
Using different versions of Drush on Drupal 7
Cloud Platform can run most stable versions of Drush, from Drush 11 to Drush 5. Drush 8 is the default, recommended version.
Cloud Platform can run most stable versions of Drush, from Drush 13 to Drush 5. Drush 8 is the default, recommended version for 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.
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:
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 infrastructure. For a printable version of this list, enter the following command:drush help --html
.