Skip to main content
Drush is a command-line shell and scripting interface for Drupal. On Upsun, you have several ways to run it: through the Upsun CLI, over SSH, or from within your app’s hooks. This guide covers how to install Drush, make it available on your path, and choose the right way to run it for your use case.

Before you begin

You need:

1. Install Drush

Add Drush to your project as a Composer dependency:
Drush needs a writable scratch space for its own caches and backups. Define mounts for both in your app configuration:
.upsun/config.yaml

2. Make Drush available on your path

Composer installs Drush to your project’s vendor/bin directory, which isn’t on your path by default. This is what makes running drush directly return drush: command not found. Add the following to a .environment file at the root of your app so Drush (and any other Composer binary) is available whenever you connect:
.environment

3. Set the site URI

Many Drush commands (such as drush uli for one-time login links) need to know your site’s URL. Set DRUSH_OPTIONS_URI from your routes in the same .environment file:
.environment

Run Drush commands

There are three ways to run Drush commands against a deployed environment, depending on your use case.

Using the CLI

The Upsun CLI has a built-in drush alias that runs a command against a remote environment without opening a full SSH session:
For example, to rebuild the cache on your current environment:
This is the fastest option for one-off commands, and it works the same way whether or not Drush is on your local machine.
The upsun CLI doesn’t support generating Drush aliases, so you’ll need to set them up manually. This is unlike the platform CLI, which includes a local:drush-aliases command for this.

Over SSH

To run Drush as part of a longer interactive session, connect over SSH and run Drush directly, or pass the command inline:
Replace feature with the name of the environment you want to target.

Set up Drush aliases manually

A Drush alias lets you run drush @myproject.main <COMMAND> from your local machine without connecting over SSH first. Since the Upsun CLI doesn’t generate these for you, create them by hand:
  1. Get the SSH host and username for each environment you want an alias for:
  2. Get the environment’s primary URL with the url command:
  3. Create a site alias file at drush/sites/<PROJECT_NAME>.site.yml in your local repository, with one entry per environment:
    drush/sites/myproject.site.yml
    root is your app’s docroot on the remote environment, the same directory Drush runs from in deploy hooks.
  4. Run commands against an alias instead of connecting manually:
You need to update the file whenever an environment is created, renamed, or deleted, since Upsun doesn’t keep it in sync automatically.

In hooks

To run Drush automatically on every deployment, add it to a deploy or post_deploy hook. This assumes Drush is already on your path. Without that, the hook fails with drush: command not found:
.upsun/config.yaml
The drush status --field=bootstrap check confirms Drupal is installed and bootstraps successfully before running further commands, which avoids failed deployments on a fresh environment that hasn’t been installed yet.

Common commands

The following Drush commands are frequently useful in an Upsun workflow:

Troubleshooting

composer require drush/drush fails

If Composer reports that it can’t find drush/drush, or blocks the install over a security advisory, this is usually a version mismatch rather than a network issue:
  • Package not found: Drush’s minimum PHP requirement increases with each major version. If your app’s PHP version is older than any available Drush release supports, Composer reports it as unable to find a matching package. Check your app’s PHP version against Drush’s current requirements, and pin to an older Drush major version if you can’t upgrade PHP yet, for example composer require drush/drush:^11.
  • Security-advisory conflict: If your composer.json includes a package like roave/security-advisories, it blocks installing versions with known vulnerabilities. Composer’s error output names the exact conflicting package and version — upgrade Drush past that range to resolve it.

drush: command not found

Confirm Drush is installed as a Composer dependency and that your path includes vendor/bin.

A command returns the wrong domain

If a command that depends on the site URI (such as drush uli) returns the wrong domain or an error, confirm DRUSH_OPTIONS_URI is set for the environment you’re running against.

Drush can’t query the database on a multisite install

On a multisite Drupal install, running a bare drush command can fail with an error like the following:
This happens because Drush can’t determine which site to target when there are multiple sites under your site directory (for example, web/sites). Specify the site with the -l (--uri) flag. Despite the flag’s name, use the site’s subdirectory name (for example, site1), not a full URL:
To run the same command across every site, loop over each site directory:

See also

Last modified on August 27, 2026