5

Is there a way of specifying a default site alias ?

couldnt find it in drushrc example nor aliases example.

motivation i am sclerotic and lazy :) usually running drush from the dir where the site is, so no alias needed. Now working in a setup where i am logged in on a different server then the actual site, so i need to always provide a site alias for each command. So the usual workflow is:

drush wipe
oh no
drush @stage wipe

so i thought a default site alias would save me from those two lines :)

13

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.

  • thanks, interesting, unfortunately not solving my problem ... i edited the question to explain what i am doing, hopefully its clearer now :) – mojzis Jul 9 '14 at 17:45
  • Okay, I added a bit to my answer to cover your intended question. :) – greg_1_anderson Jul 9 '14 at 17:57
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.