If you have ever tried to install Drush for administering Drupal on any shared hosting package, you will know it is a devilishly difficult task to get right!
Some hosting firms supply some written information on how to achieve this. 1&1 is not one of them. Having just slogged through the whole process myself, I thought I would share the steps I found worked for me (note, these steps are nearly all adapted from the official Drush install instructions and a few other sources around the web, see the list below for acknowledgements and references)
Before installing any sites, I set all my domains to use PHP v5.5
Open an SSH terminal session to your hosting account (I recommend using the Bitvise SSH client) and type the following to install the Composer package:
1 | curl -sS https://getcomposer.org/installer | php5.5 |
Next, run Composer and instruct it to install Drush and all dependencies:
1 | php5.5-cli composer.phar global require drush/drush:dev-master |
Create a bash profile file (.profile) in the root of your webspace with the following contents (N.B. please see the comments below as some have found it necessary to replace “$HOME” with “./composer” or fully typing in your complete home path in the first “export” instruction):
1 2 | export PATH="$HOME/vendor/bin:$PATH" export DRUSH_PHP=/usr/bin/php5.5-cli |
Edit the file /vendor/drush/drush/drush.php and add the following ‘if statement’ (lines 4-15) between the first <?php line and the following /** line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/usr/bin/env php <?php if (!defined('STDIN')) { define('STDIN', fopen('php://stdin', 'r')); } if (!defined('STDOUT')) { define('STDOUT', fopen('php://stdout', 'w')); } if (!defined('STDERR')) { define('STDERR', fopen('php://stderr', 'w')); } /** * @file * drush is a PHP script implementing a command line shell for Drupal. * * @requires PHP CLI 5.3.0, or newer. */ |
Log out of your SSH session and log back in again to load the newly create bash profile.
You should now have a fully operational installation of Drush.
References
1&1 Hosting – http://www.1and1.co.uk/
Tweaks to drush.php by Jeremy Hislop – http://jheslop.com/2012/10/30/drush-on-1and1-shared-hosting-cg/
Thank you very much for your helpful article. This has saved me a lot of time. It did take me a while (a few hours of frustration) to work out I needed to replace $HOME with my own home path. I had thought $HOME was some kind of named constant :/
You are very welcome, Ben. Not sure why $HOME didn’t work in your instance as that is exactly what is working on my 2 accounts with this setup. I’ll investigate at some point and will update the article if necessary.
Thank you for this article, I tested many others tutoriels before, these didn’t work and your solution works perfectly. thanks to comments from Ben, I replaced $HOME by ~/.composer because it didn’t find the directory “vendor”(it is in the directory “.composer”).
Thanks much for sharing this, the ~/.composer method worked for me as the path to drush.php was /.composer/vendor/drush/drush/drush.php
I followed these instructions, but I still get an error that begins with “X-Powered-By: PHP/4.4.9”
I don’t understand why my php version is not picking up the .profile instruction to use the php5.5-cli version.
Same as Chris I had to add ~/.composer with the ~ instead of your “.”.
I still get an error: X-Powered-By: PHP/4.4.9
Content-type: text/html
Fatal error: Call to undefined function: drush_startup() in /homepage
s/11/dxxxxxxxx/htdocs/.composer/vendor/drush/drush/drush on line 115
This does not work, server continue to execute old PHP 4. I create an alias in .profile and now calling drush works.
alias drush='/usr/bin/php5.5-cli ~/.composer/vendor/drush/drush/drush'
Not the answer you re looking for? Browse other questions tagged 7 drush or ask your own question .