Skip to main content

Drush Commands

Learn how to use Drush commands on your Pantheon site.


This section provides information on useful Drush commands to help you manage your site on Pantheon.

Execute a Drush Command on a Pantheon Site Environment

You can execute a command on any remote site that you see in the list of site aliases. Refer to Drush Aliases for more information. The syntax is:

drush @pantheon.SITENAME.ENV COMMAND
Warning:
Warning

Do not use Drush to update Drupal core on Pantheon. Pantheon uses Pressflow and includes some additional functionality. This conflict with Drush, which assumes that a site is using vanilla Drupal and erroneously overwrites Pressflow. Refer to Core Updates for more information.

Registry Rebuild

Info:
Note

Registry Rebuild is deprecated for the latest version of Drupal, but can still be used on Drupal 7.

Drupal's list of PHP classes and files can become corrupted or out-of-date, typically when moving code. If clearing the cache doesn't resolve the issue due to a required class during bootstrap, the registry may need to be rebuilt. Pantheon has installed registry_rebuild as an available Drush command on every site, which can be executed via Terminus.

Do not attempt to install the module on your site. This command is provided as-is and without warranty. You must create a backup before continuing.

terminus drush <site>.<env> -- rr

Drupal 7

Use the registry rebuild command for Drupal 7 and older versions of Drupal.

Drupal (Latest)

Use the drush cache:rebuild command for the latest version of Drupal. This command serves the same function that as the registry rebuild command for older Drupal versions.

Filter Drush Responses

Use the --filter command to extract relevant information from terminus drush responses.

For example, to get the line containing information about your installed version of PHP from the Drupal status report page:

terminus drush mysite.env -- core:requirements --filter='title=php'
+-------+----------+--------------------------------------------------+
| Title | Severity | Summary                                          |
+-------+----------+--------------------------------------------------+
| PHP   | Info     | 7.3.14 (<a href="/admin/reports/status/php">more |
|       |          | information</a>)                                 |
+-------+----------+--------------------------------------------------+

You can add --field=Summary to the end of the command to extract only the Summary field without any of the table formatting. The result is a simple string:

terminus drush <site>.<env> -- core-cli
7.3.14 (<a href="/admin/reports/status/php">more information</a>)

Drush Commands That Alter Site Code

You must set your Dev environment to SFTP mode in the Pantheon Dashboard to use commands that alter site code, such as pm-download (dl).

Add Custom Drush Commands

Drush core commands are available for your use, but you can also add a command that you regularly use, for example, Drush Search and Replace (sar).

  1. Set your Development Mode to Git in the Dev environment.

  2. Clone locally.

  3. Create a drush folder in the Drupal root.

  4. Add the sar Drush command to the Drush folder.

  5. Commit drush/sar.

  6. Push your code to Pantheon.

  7. Clear your Drush cache on each environment. Example:

    drush @pantheon.SITENAME.dev cc drush

You should place Drush commands in drush/Commands if using Drupal.

More Resources