Drupal - drush default site alias

Drush automatically defines the alias @self to refer to the currently bootstrapped site. So, if you have identified a site via cwd (that is, cd /path/to/sites/mysite, where sites/mysite is the folder that contains settings.php), then you could run:

drush sa @self

This will tell Drush to print out a site alias for the current site. You can then copy this to an alias file and give it a handy name for later use. If you're doing this for a remote site, try adding --with-db if you'd like to include the database record inside the site alias. You're better off leaving out the database information for local sites, though, as you can get inconsistent results if the db info in your alias does not match the db info in settings.php.

If you want to disable cwd-based site selection, then define 'root' and 'uri' in any drushrc.php file:

$options['root'] = '/path/to/drupal';
$options['uri'] = 'http://mysite.org';

There is no way to specify an alias in a Drush configuration file, but you could use the site-set command from the command line:

$ drush site-set @stage

If you wanted this command to be persistent, you could run it from your .bashrc.


It is also possible to set default uri in settings.php inside the root of your drupal folder.

Like this:

$base_url = 'http://localhost/...';

Then you don't need to update your drushrc.php file every time you start a new project.

Tags:

Drush