Development style - settings.php file and Drush

sambojambo's picture

Hi everyone,

Hope I'm posting in the right place for this question/discussion. I'm starting to use Drush frequently. I find it a great natural extension to the way I work as I develop on Linux.

I've come up against a bit of a problem though. I'm not sure but I assume that drush parses the settings file to do it's stuff. The way I develop I usually work with a number of sub domains , dev , test , staging.

My settings file deals with this by looking at the $_SERVER['SERVER_NAME'] to determine which domain the code is on and defining which DB to connect to.

<?php
$host
= $_SERVER['SERVER_NAME'];
switch(
$host )
{
  case
'drupal-dev.idevelop.com': # Development server
   
$db_url   = 'mysqli://drupal@localhost/d6_dev';
   
$base_url = 'http://'.$host
    break;
   
  case
'drupal-test.idevelop.com': # Testing server
   
$db_url   = 'mysqli://drupal@localhost/d6_test';
   
$base_url = 'http://'.$host;  
    break;
   
  case
'drupal-staging.idevelop.com': # Tag  server
   
$db_url   = 'mysqli://drupal@localhost/d6_staging';
   
$base_url = 'http://'.$host;  
    break;
}
?>

This appears to stop drush in it's tracks.

I probably get round it by doing a multi-site setup - but I don't want to maintain numerous copies of the settings.php file.

Does anyone else develop in a similar way? Any suggestions about how to deal with this would be greatly appreciated.

Sam

Comments

hi similar problem kind of...

duckx's picture

hi, not exactly a solution to your problem but the way i have mine setup is via multi-site setup, problem is that i'm not sure how i setup a dev and staging version of it. im managing about 5 sites using the multi-site setup and just back up frequently.

Bootstraps Drupal

sambojambo's picture

Thanks for the reply duckxtales - the only other way that has occurred to me is to use a multi-site setup with a minimum settings file for each site, that includes a common_settings.php file where you can put modified $conf array and that sort of thing?

I might have a chance to give it ago today - if I do I'll let you know if it works.

Bit of a rush last night when posting - I've had a little dig into the drush code this morning and it doesn't 'parse' the settings file but bootstraps drupal (of course!!). So not quite sure why it's not picking up on the switch statement? But maybe a multi-site setup with a included 'common_settings' file will be closer to the 'Drupal way'.

symlinks

alienresident's picture

We solved this by using symlinks to point to the right settings file on different servers.

We also use sylimks to keep one set of files modules and the themes for all three environments

so in the site directory we would have:

all
  |--> modules
  |--> libraries
example.com
  |--> files
  |--> modules
  |--> themes
  |--> settings
      |-->example.com.settings.php
      |-->dev.example.com.settings.php
      |-->localhost.settings.php
  |-->settings.php > example.com.settings.php
dev.example.com
  |--> files > ../example.com/files
  |--> modules > ../example.com/modules
  |--> themes > ../example.com/themes
  |-->settings.php > ../example.com/setttings/dev.example.com.settings.php
localhost
  |--> files > ../example.com/files
  |--> modules > ../example.com/modules
  |--> themes > ../example.com/themes
  |-->settings.php > ../example.com/setttings/localhost.settings.php

And with drush we use the uri argument to make sure we are working on the right site
i.e. clear the localhost cache
drush --uri=http://localhost cc

let me know if that helps

srush sets uo the

moshe weitzman's picture

drush sets up the superglobals that drupal uses. in your case, switch to $_SERVER['HTTP_HOST'] and you will be good. see _drush_bootstrap_drupal_site_validate()

A solution

sambojambo's picture

Cool guys thanks for your comments - I managed to solve the problem before I saw your replies.

I came up with a similar solution to alienresident . I created a common folder (which actually now as I type this, may as well reside in the 'all' folder - would make it even tidier...) and common_settings.php.

Then a normal multi-site set up but with only site specific settings in the settings folder for each site and the common_settings.php included at the top (as below).

|-- all
|   |-- CVS
|   |-- README.txt
|   |-- libraries
|   |-- modules
|   |-- themes
|-- common
|   |-- CVS
|   |-- common_settings.php
|-- site-dev.example.com
|   |-- CVS
|   |-- settings.php
|-- site-staging.example.com
|   |-- CVS
|   |-- settings.php
|-- site-test.example.com
    |-- CVS
    |-- settings.php

My simple settings file in site-dev.example.com .

<?php
include 'sites/common/common_settings.php';

$base_url = 'http://site-dev.example.com';
$db_url= 'mysqli://drupal:iamdrupal@localhost/site_dev';
?>

And drush now works sweet! just pass in the switch --uri to interrogate the individual sites.

Thanks again

Sam

Drush aliases

brandon.holtsclaw's picture

This post is well over a year old but just for those coming from Google search or somewhere else on Drupal.org you can also setup @aliases for your sites and configs too directly in a drush specific file located in ~/.drush/ among other places in its path, "drush topic aliases" should get you a start.

--
Brandon Holtsclaw
Personal, Come see my hobbies: http://www.brandonholtsclaw.com
Email: hello AT the domain listed above :)

drush

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: