Sorry, you need to enable JavaScript to visit this website.

How to setup drush aliases for your Drupal 8/9 website

Submitted by abhaisasidharan on Wed, 10/13/2021 - 15:58

Firstly, make sure you have ssh access to the server (dev, test and/or prod). Your ssh command looks something like this: ssh user@your-website.com or ssh user@100.230.222.122. Drush alias works by using this username and domain/ip address combination to login to the server and execute the command and then return back to your command line. In your project root, create a drush folder and inside it, create a sites folder. Now you put your site alias config in that folder. Name it something like project.site.yml. So your aliases defined inside it would be something like the following:

dev:
  root: /var/www/html/dev-website/web
  uri: your-website.com
  host: your-website.com
  user: ubuntu
  ssh:
    tty: 0

So your alias here would be @project.dev. You can test this by running drush @project.dev status from the project root folder. The above config is for a server with Linux user named "ubuntu". If you want the drush command to be interactive you can set the tty to 1.

Here's the folder structure.

project-root/
  |- web/
  | |- modules/
  | |- themes/
  | |- index.php
  |- drush/
  | |- sites/
  | | |- project.site.yml 
  |- composer.json