4

I have been using Drush 4 and 5 with no problem. Now that I have downloaded and installed new Drush 7.0-dev using composer, I am having problem i.e it doesn't by-default detect drupal installation when I am on sites sub-folder,

Drush running on sites-root directory,

drupal7/sites/example.com/modules/views$ drush status

 Drupal version                  :  7.30                               
 Site URI                        :  http://example.com              
 Database driver                 :  mysql                              
 Database hostname               :  localhost                          
 Database port                   :                                     
 Database username               :  example_user                    
 Database name                   :  example_db                     
 Database                        :  Connected                          
 Drupal bootstrap                :  Successful                         
 Drupal user                     :                                     
 Default theme                   :  bartik                             
 Administration theme            :  seven                              
 PHP executable                  :  /usr/bin/php                       
 PHP configuration               :  /etc/php5/cli/php.ini              
 PHP OS                          :  Linux                              
 Drush version                   :  7.0-dev                            
 Drush temp directory            :  /tmp                               
 Drush configuration             :                                     
 Drush alias files               :                                     
 Drupal root                     :  drupal7
 Site path                       :  sites/example.com               
 File directory path             :  sites/example.com/files         
 Temporary file directory path   :  /tmp                            

Drush running under sites-subdirectory,

drupal7/sites/example.com/modules/views$ drush status

 Drupal version         :  7.30                               
 PHP executable         :  /usr/bin/php                       
 PHP configuration      :  /etc/php5/cli/php.ini              
 PHP OS                 :  Linux                              
 Drush version          :  7.0-dev                            
 Drush temp directory   :  /tmp                               
 Drush configuration    :                                     
 Drush alias files      :                                     
 Drupal root            :  drupal7 

So, how do I configure Drush, is there anything I can do to make it work, I don't want to use --uri or -l flag or any other options everytime.

Update

Also when I download modules it get downloaded on sites/all/modules directory

drupal7/sites/example.com/modules$ drush dl webform
Project webform (7.x-3.20) downloaded to drupal7/sites/all/modules/webform.                                     [success]

But if I am on sites-root directory it works fine,

drupal7/sites/example.com$ drush dl webform
Project webform (7.x-3.20) downloaded to /home/sysop/project/drupal7/htdocs/sites/heisenberg.com/modules/webform.                          [success]
  • you seem to have some discrepancies in the paths ? ie the first and second status seem to have run in exactly the same place ? and what is htdocs under drupal7 ? – mojzis Aug 6 '14 at 0:26
4
+50

You need to add an alias conf file named YOUR_SITE_NAME.aliases.drushrc.php in sites\all folder with that code.

// The site in sites/YOUR_SITE_NAME/ 
$aliases['YOUR_SITE_NAME.local'] = array(
  'uri' => 'YOUR_SITE_NAME_URI',
  'root' => '/path/to/drupal_root_folder',
  'path-aliases' => array(
    '%dump-dir' => '/tmp'
  ),
);

Then clear cache : drush cache-clear drush.

Test your alias : @YOUR_SITE_NAME.local status.

To run a command, for the sake of example : @YOUR_SITE_NAME.local mb MODULE_NAME hook1 hook2 --write


UPDATE : in order to create automatically Drush site aliases for many sites, place this code in your aliases.drushrc.php file. Drush will look for aliases.drushrc.php in the ".drush" folder in your home directory (see this post to get sure where to put this file).

$aliases = array();
$drupal = '/var/www/drupal';

// Automatic alias for each Drupal site
$site = new DirectoryIterator($drupal . '/sites');
while ($site->valid()) {
  // Look for directories containing a 'settings.php' file
  if ($site->isDir() && !$site->isDot() && !$site->isLink()) {
    if (file_exists($site->getPathname() . '/settings.php')) {
      // Add site alias
      $basename = $site->getBasename();
      $aliases[$basename] = array(
        'uri' => $basename,
        'root' => $drupal,
      );
    }
  }
  $site->next();
}

// Get all site aliases
$all = array();
foreach ($aliases as $name => $definition) {
  $all[] = '@' . $name;
}

// 'All' alias group
$aliases['all'] = array(
  'site-list' => $all,
);

You can also read this : create your own drush aliases. You could even think about managing synchronization between remote and local systems (source).

EDIT : as per ericx comment, consider adding bash-completion. Drush comes with a bash-completion file, drush.completion.sh, which offer alias completions.

  • 1
    so every time I create new site, there I need to write drush alias, this won't be helpful for multiple site I am using like 1000 or so. :) previous version of drush works fine out of the box why is it so ? – shrish Aug 1 '14 at 9:01
  • where should aliases.drushrc.php file be present. I am confused :) – shrish Aug 1 '14 at 9:38
  • I updated the answer. By default in the ".drush" folder in your home directory – Kojo Aug 1 '14 at 9:52
  • I see that alias file is being used by drush,while running the drush command, but the alias is not working for me – shrish Aug 1 '14 at 9:58
  • 2
    I can also recommend that you consider adding bash-completion. drush comes with a bash-completion file, drush.completion.sh. Amongst other things, it will offer alias completions for you. Makes it a little less painful. – ericx Aug 4 '14 at 17:29
2

I would suggest getting the 6.x version which is the stable version for D7 (yes, the versioning is slightly confusing :). You should be able to isntall it with

composer global require drush/drush:6.*
  • Drush 4,5,6 works just fine, problem with Drush 7-dev version may be. – shrish Aug 6 '14 at 4:09
0

Take a look at Drush Aliases.

They essentially let you target your Drupal installations to run your drush commands on.

0

This may sound silly, but make sure there is a settings.php file in drupal7/sites/example.com/ and drush/drupal has access to edit that file

--or--

try using the --uri parameter:

drush dl --uri=http://example.com webform

0

In my case it turned out that I needed to install mysql-client:

apt-get install mysql-client

I had the following situation: drush 4, 5 and 6 worked fine for me. drush 7, 8 don't work (different errors, including that ones you're describing). And my MySQL database was located on a separate server.

HTH, Alexander

0

I was not able to run drush from inside the drupal directory post reinstalling drush. It turns out there was a symlink to drush inside that directory that was causing recursion and therefore drush was failing. Removed the symlink and was able to run drush from the directory again.

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.