Drupal 9: How to add a Drush site alias to manage your live site remotely

First thing you should do is install an SSH key on the remote server. You can't connect to the site without it.

In your local site install, at the project root:

Create the configuration file at PROJECTROOT/drush/sites/self.sites.yml:

# @code
# # File: self.site.yml
live:
  host: IP_ADDRESS_OF_SITE
  user: SSH_USERNAME
  root: FULL_PATH_TO_DRUPAL_ROOT
  uri: https://yourdomainname.com
  paths:
    drush-script: '/FULL_PATH_TO_PROJECT_ROOT/vendor/bin/drush'
# @endcode

For example, for this site my file looks like this:

# @code
# # File: self.site.yml
live:
  host: 178.128.225.231
  user: ADMIN_USERNAME
  root: '/home/public_html/web'
  uri: https://dannylufkin.com
  paths:
    drush-script: '/home/public_html/vendor/bin/drush'
# @endcode

What can you do with drush site alias?

Sync your production database to your local.

drush sql-sync @self.live @self

Sync your production files to your local

drush rsync @self.live:%files @self:%files

For more information:

Tags