Local drush aliasing

By Erik , Sat, 05/08/2021 - 13:22

I used to build websites, lots of websites, both for work and for personal endeavors. But alas, I'm down to less than a handful now. At work, we have very detailed processes involving docker builds, contained local environments, but since I'm the only one who maintains these sites, I tend to be a little more bare bones.

Many years ago, I discovered the Drush quickstart and Drush run-server commands which made demo'ing and prototyping very quick. Especially if I was just working on a patch or fix for an issue instead of working on a particular site.

Drush run server works with the built-in PHP CLI web server which can function just fine for most local Drupal development that doesn't need special Apache features.

The biggest problem I have run into over the years is being consistent about which port and that you usually have to start the server with --uri=127.0.0.1:<port> every time.

Recently I have begun to include an @local drush alias with the project that helps to keep these consistent. I started off defining the uri and root parameters in drush/sites/self.site.yml

local:
  root: /path/to/project/web
  uri: http://127.0.0.1:9898

This, however, still necessitated running rs with a port and path:

drush @local rs :9898/admin

Since I was trying to give each project it's own port, this was always a little confusing to remember which port went with which project. Then I discovered the command properties for the alias file.

After some experimentation, I came up with the following snippet:

  command:
    runserver:
      options:
        default-server: '127.0.0.1:9898/admin'

This allowed me to bring up a server process, launch the browser and be in at the admin section with:

drush @local rs

which can then be the default for any project.

Comments