4

I want to create drush site aliases for my sites in order to use rsync. However, I'm not sure what URI means. Is it the (sub)domain I have assigned to my site, or the sites/ folder it is in? If it's the sites/ folder and I am using sites/default , does that make the URI "default"?

$aliases['demosite.drupal7.local'] = array (
  'uri' => 'demosite.drupal7.local',
  'root' => '/var/www/drupal7',
);

Update

I found my answer in drush/examples/example.aliases.drushrc.php.

'uri': This should always be the same as the site's folder name in the 'sites' folder.

5

Okay, I wrote that line you're quoting above ("uri': This should always be the same as the site's folder name in the 'sites' folder."), but unfortunately that is an oversimplification that is not always correct, especially when using a Drupal 7 site.

This is what I say about "uri" in the Definitive Guide to Drupal 7:

The URI used on the command line should be the same as when the site is being accessed from a web browser. It is also possible to use the name of the folder that contains the settings.php file for that URI (e.g. --uri=default). This works, and is, in fact, equivalent to [back reference to an example that runs core-status using the cwd to select the Drupal site] in terms of the site URI that Drush will use when calling in to Drupal; you can confirm this by comparing the output of the "Site URI" line in [back reference to same listing] with this output. Having a correct site URI is not always required, but some modules might need it if, for example, they are generating absolute URLs or making HTTP requests back to the same host; it's therefore advisable to set a correct URI whenever possible.

This quote is 100% correct for Drupal 7, but the situation is slightly more complicated with Drupal 6. In D6, the value of the --uri option (and correspondingly, the URI used to access the site from a browser), will sometimes be written into the database. For example, if your settings.php file is stored at sites/mysite.org/settings.php, and your URI (from the browser) is http://mysite.org, then you might in some circumstances find paths "sites/mysite.org/files/myuploadfile.png" in the database. The URI from the browser is converted to the name of the folder containing settings.php before being used by Drupal (for some uses), whereas the --uri option passed to Drush is always used as-is. Because of the fact that your site folders are written to the database, it's often handy to continue to use the sites folder "mysite.org" for your dev site "http://dev.mysite.org", and of course there's always the possibility that your sites folder is called 'default' (often a good idea on D6). So, while --uri=dev.mysite.org and --uri=mysite.org and --uri=default may will all work (presuming a site http://dev.mysite.org which is a dev copy of http://mysite.org with its settings.php file in the default folder) to select the site for Drush, there are some edge cases where --uri=default is better in that the other options will not match what your modules are seeing when the same code. On the flip side, there are also other edge cases where --uri=mysite.org is what you need to align your runtime variables with what your module will see with the browser (c.f. above dgd7 quote). So the truth of the matter is that there is no value that is absolutely best for D6. The simplified advice you quoted above was used in the example file because things can really go wrong if you use --uri=mysite.org instead of --uri=default, AND a path is generated and written to the database, AND you migrate your database to another instance of the site, breaking the path.

For D6, the most pragmatic thing to do would be to name your sites folder 'sites/mysite.org' instead of 'sites/default' (and make sure that it is also 'sites/mysite.org' for http://dev.mysite.org).

I changed the advice in examples/example.aliases.drushrc.php as follows:

  • 'uri': In Drupal 7, the value of --uri should always be the same as when the site is being accessed from a web browser (e.g. http://mysite.org, although the http:// is optional). In Drupal 6, the value of --uri should always be the same as the site's folder name in the 'sites' folder (e.g. default); it is best if the site folder name matches the URI from the browser, and is consistent on every instance of the same site (e.g. also use sites/mysite.org for http://dev.mysite.org).
  • 1
    Rather than saying that "http:// is optional", it'd be more accurate to say that if the URI specifies a protocol, it will be ignored. For example, you can't specify "https://", which is unfortunate for drush commands like 'user-login'. – mc0e Apr 8 '13 at 12:42
  • Greg, may I ask you to have a look at this question drupal.stackexchange.com/q/276285/15055 which I tried to answer in the comments but I guess you can explain it much better maybe or also know some reference that can be referred to in a proper answer? – leymannx Feb 8 at 14:23
-1

Found my answer in drush/examples/example.aliases.drushrc.php : "uri': This should always be the same as the site's folder name in the 'sites' folder."

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.