Drush installation

Notes about installing Drush. See Installing Drush 6 and 7 on Shared Hosting Accounts With Composer for installation instructions on a shared host.

Quick install with Composer

This assumes that PHP is at /usr/bin/php, ~/bin is in your PATH, ~/.bash_profile is your shell (bash) startup file and Drupal is in ~/public_html…

ssh [domain]
cd ~
curl -sS https://getcomposer.org/installer | php
mkdir bin
mv composer.phar bin/composer.phar
echo '# Drush. https://www.drupal.org/node/2366283' >> .bash_profile
echo 'alias composer="/usr/bin/php ~/bin/composer.phar"' >> .bash_profile
source .bash_profile
composer global require drush/drush:dev-master
echo 'alias drush="~/.composer/vendor/bin/drush"' >> .bash_profile
source .bash_profile
cd public_html
drush status

Note: Swap /usr/bin/php for /usr/bin/php-cli or wherever the php client is. You can find it with whereis php or whereis php-cli.

Here’s an example on my test account:

me@pc ~ $ curl -sS https://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /home/test/composer.phar
Use it: php composer.phar
me@pc ~ $ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.4:/opt/nvidia-cg-toolkit/bin:/usr/games/bin
me@pc ~ $ echo "PATH=$PATH:$HOME/bin" >> .bash_profile
me@pc ~ $ source .bash_profile
me@pc ~ $ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.4:/opt/nvidia-cg-toolkit/bin:/usr/games/bin:/home/test/bin
me@pc ~ $ mkdir bin
mkdir: cannot create directory ‘bin’: File exists
me@pc ~ $ mv composer.phar bin/
me@pc ~ $ echo '# Drush. https://www.drupal.org/node/2366283' >> .bash_profile
me@pc ~ $ echo 'alias composer="/usr/bin/php ~/bin/composer.phar"' >> .bash_profile
me@pc ~ $ source .bash_profile
me@pc ~ $ composer global require drush/drush:dev-master
Changed current directory to /home/test/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing symfony/var-dumper (v2.6.3)
    Downloading: 100%

  - Installing d11wtq/boris (v1.0.10)
    Downloading: 100%

  - Installing pear/console_table (1.2.1)
    Downloading: 100%

  - Installing symfony/yaml (v2.6.6)
    Downloading: 100%

  - Installing drush/drush (dev-master f6b2ef7)
    Cloning f6b2ef7dc22f49f4dc65e1f3250731f89e58da4c

symfony/var-dumper suggests installing ext-symfony_debug ()
pear/console_table suggests installing pear/Console_Color2 (>=0.1.2)
Writing lock file
Generating autoload files
me@pc ~ $ echo 'alias drush="~/.composer/vendor/bin/drush"' >> .bash_profile
me@pc ~ $ source .bash_profile
me@pc ~ $ drush status
 PHP executable         :  /usr/bin/php                                      
 PHP configuration      :  /etc/php/cli-php5.3/php.ini                       
 PHP OS                 :  Linux                                             
 Drush script           :  /home/test/.composer/vendor/drush/drush/drush.php 
 Drush version          :  7.0-dev                                           
 Drush temp directory   :  /tmp                                              
 Drush configuration    :                                                    
 Drush alias files      :

You can use a different branch instead of dev-master if you’d like. If you want to change simply run the composer global require command, e.g:

me@pc ~ $ composer global require drush/drush
Changed current directory to /home/test/.composer
Using version ^6.6 for drush/drush
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Updating drush/drush (dev-master f6b2ef7 => 6.6.0)
    Checking out 1779c6c37d56235935e99d849bb4c910b632428e

Writing lock file
Generating autoload files
me@pc ~ $ drush status
 PHP executable        :  /usr/bin/php                
 PHP configuration     :  /etc/php/cli-php5.3/php.ini 
 PHP OS                :  Linux                       
 Drush version         :  6.6.0                       
 Drush configuration   :                              
 Drush alias files     :                              

me@pc ~ $ composer global require drush/drush:7.0.0-rc1
Changed current directory to /home/test/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Updating drush/drush (6.6.0 => 7.0.0-rc1)
    The package has modified files:
    M drush.bat
    M drush.complete.sh
    Discard changes [y,n,v,s,?]? y
    Checking out 8e3276d400eebf4d2d0a4d7c623766d6b610ecf0

Writing lock file
Generating autoload files
me@pc ~ $ drush status
 PHP executable         :  /usr/bin/php                
 PHP configuration      :  /etc/php/cli-php5.3/php.ini 
 PHP OS                 :  Linux                       
 Drush version          :  7.0.0-rc1                   
 Drush temp directory   :  /tmp                        
 Drush configuration    :                              
 Drush alias files      :                              

Potential problems during installation

Unexpected character / syntax error

If you get the following error when running the composer installer through php…

-bash-3.2$ curl -sS https://getcomposer.org/installer | php PHP Warning: Unexpected character in input: ‘' (ASCII=92) state=1 in - on line 574 PHP Parse error: syntax error, unexpected T_SL in - on line 849

Then the changes are that you are running PHP < 5.3. Composer can only run on 5.3 upwards.

The suhosin.executor.include.whitelist settings is incorrect

If you get the following error when getting composer:

Some settings on your machine make Composer unable to work properly. Make sure that you fix the issues listed below and run this script again:

The suhosin.executor.include.whitelist setting is incorrect.

Then add the following to your php.ini:

suhosin.executor.include.whitelist=phar

You could also add it to the php call in your bash alias:

alias composer="/usr/bin/php-cli -d suhosin.executor.include.whitelist=phar ~/bin/composer.phar"

Note: Swap /usr/bin/php for /usr/bin/php-cli or wherever the php client is. You can find it with whereis php or whereis php-cli.

Permission denied

If you get ‘/home/finnguil/.composer/vendor/bin/drush: line 7: /home/finnguil/.composer/vendor/drush/drush/drush: Permission denied’ when attempting to run drush, then make it executable:

chmod u+x ~/.composer/vendor/drush/drush/drush

exec() has been disabled for security reasons

If you get exec() has been disabled for security reasons ... or passthru() has been disabled for security reasons then you could try to undisable everything via php.ini:

echo 'disable_functions=' >> ~/.drush/php.ini

However if you’re on e.g. shared hosting and disable_functions was set in the system’s php.ini, then you won’t be able to prevent disabled functions being disabled.

Needs a higher bootstrap

If you get the following when trying to run drush (with e.g. pm-list)…

Command pm-list needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command. The drush command ‘pm-list’ could not be executed. Drush was not able to start (bootstrap) the Drupal database. Hint: This may occur when Drush is trying to: * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the –uri parameter on the command line. See drush topic docs-aliases for details. * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.

…Then try the following:

  1. It could be a problem with the bootstrap. Check that you can actually run the site. Does it load in the browser?
  2. Then try setting your host line in settings.php to the following (assuming your database is at localhost):

    ‘host’ => php_sapi_name() == ‘cli’ ? ‘127.0.0.1’ : ‘localhost’,

  3. Or try setting the port number in settings.php.
  4. Make sure you’re running it in public_html (or wherever Drupal is installed).

You can run drush with -d to get debug info.

PDO support is required

When I ran drush with debug I found the following:

PDO support is required.

The solution was to add the following two lines to ~/.drush/drush.ini:

extension=pdo.so
extension=pdo_mysql.so

Your requirements could not be resolved

If you get the following when running composer global require drush/drush:dev-master

Your requirements could not be resolved to an installable set of packages.

Problem 1 - Installation request for drush/drush dev-master -> satisfiable by drush/drush[dev-master]. - drush/drush dev-master requires php >=5.4.5 -> your PHP version (5.3.29) does not satisfy that requirement.

Installation failed, deleting ./composer.json.

…Then try installing a different version of drush. Version 7 should support 5.3. Require it as follows:

composer global require drush/drush:7.*

The following website shows you which versions of PHP are supported by the different version of drush: Install - Drush docs

drush: No such file or directory

I’ve found that composer sometimes fails to create symlinks in .composer/vendor/bin. If this happens then you’ll get something like the following message when you try to call drush:

-bash: /home/test/.composer/vendor/bin/drush: No such file or directory

To fix this you can manually create the symlinks. I just created all those that were created on a different successful installation, as follows:

me@pc ~/public_html $ cd ../.composer/vendor/bin/
me@pc ~/.composer/vendor/bin $ ln -s ../d11wtq/boris/bin/boris boris
me@pc ~/.composer/vendor/bin $ ln -s ../drush/drush/drush drush
me@pc ~/.composer/vendor/bin $ ln -s ../drush/drush/drush.bat drush.bat
me@pc ~/.composer/vendor/bin $ ln -s ../drush/drush/drush.complete.sh drush.complete.sh
me@pc ~/.composer/vendor/bin $ ln -s ../drush/drush/drush.php drush.php
me@pc ~/.composer/vendor/bin $ chmod a+x *

So you should see the following symlinks:

me@pc ~/.composer/vendor/bin $ ls -l
total 8
drwxrwxr-x 2 test test 4096 Jun  8 17:36 ./
drwxrwxr-x 8 test test 4096 Jun  8 17:33 ../
lrwxrwxrwx 1 test test   25 Jun  8 17:36 boris -> ../d11wtq/boris/bin/boris
lrwxrwxrwx 1 test test   20 Jun  8 17:36 drush -> ../drush/drush/drush
lrwxrwxrwx 1 test test   24 Jun  8 17:36 drush.bat -> ../drush/drush/drush.bat
lrwxrwxrwx 1 test test   32 Jun  8 17:36 drush.complete.sh -> ../drush/drush/drush.complete.sh
lrwxrwxrwx 1 test test   24 Jun  8 17:36 drush.php -> ../drush/drush/drush.php

References

Last modified: 06/10/2015 Tags: , ,

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top