Pantheon Community

Tip Tuesdays: Command-Line Tools for Websites

If you’re a Drupal developer, you may use the Drush command-line tool to run operations. Many of the things you can do in the web-based admin you can run via Drush commands. When running a Drupal site on your local machine, you often need to write some code, then clear the cache and test your changes. With Drush, you can just run this command:

drush cr

Did you know you can run these types of commands on your Drupal site, even on your Pantheon environments? Through Terminus, our command-line tool, you can do just that:

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

If I replace with my site’s name and with “dev”, “test”, “live” or the name of the multidev, then running that command will clear the Drupal cache on that environment.

To see all the Drush commands available with your site:

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

Each command has options, which you can also find more about via command-line:

terminus drush <site>.<env> -- help user-login

This will show you available options for the “drush user-login” command, which will give you a one-time login link for any user. It’s a great tool for debugging user access issues on your site.

If you’re familiar with Drush, you might use Drush Aliases to connect to your Pantheon site and run Drush commands, but in most cases, it’s just easier, in my experience, to run them through Terminus. (Drush Aliases on Pantheon sometimes need to be updated as database servers are migrated, while Terminus always connects you to the current server.)

Terminus does a lot more as well. Anything that you can do in the Pantheon Site Dashboard, User Dashboard, or Org Dashboard can be done via Terminus (and even a few more things). As described above, it also provides a way to run Drush or WP-CLI commands (a similar tool for WordPress sites) directly on your server.

If you’re unfamiliar with Terminus, install it and give it a try. Info on how to do so, example commands, and a full list of commands are available in our Terminus Docs. If you’re using Windows, we recommend running Terminus in the Windows Subsystem for Linux.

I hope this tip helps y’all level up your developer game. Got a favorite Terminus/Drush/WP-CLI command or any questions? Let’s talk about it below!

2 Likes

I don’t have to use it much on Pantheon, but my fave WP-CLI command has to be search-replace:

terminus remote:wp $site.$env -- search-replace "://live-example.pantheonsite.io" "://test.example.com" --all-tables --verbose

So handy for getting those URLs to sync up between environments.

3 Likes

One that I use frequently as part of a script that loops through all of our Pantheon sites is when I want to know which sites have a module and if it’s installed or not. While this is one line in the lopped script, our script will output all sites that match this module:

terminus remote:drush $SITE.$ENV -- pm-list --type=Module --status=enabled | grep metatag
3 Likes