Install Drush on cPanel shared hosting

Drush is a command line shell and scripting interface for the popular Drupal CMS. To install Drush on almost all shared linux hosting platforms requires just a few steps at the command prompt.

For the purposes of this guide, I’ll assume you already know how to connect to your hosting server using SSH to get a command prompt. Mac and linux users will achieve this using the terminal application built into the operating systems, and Windows users will use something like PuTTY.

Once you connect using SSH you will find yourself in the the home directory of your hosting account. To the left of your cursor prompt you should see a tilde character ~ which is shorthand for your home directory.

To confirm you are in the right place, run
ls -la The output should list the contents of your home directory, including your public_html/ public_ftp/ mail/ and a whole bunch of other stuff. If you run
pwd then you will probably get something like /home/username

Now we are in the right place, fetch the version 6 branch of Drush (the recommended branch at the time of writing) with:

Some SSH connections may complain with ERROR: cannot verify’s certificate. If you see this error, just run the following command instead

If you can’t use wget, then download the file from the URL to your local PC and upload it using your SFTP client of choice (such as Filezilla for example) to your home directory. If you download the link using a browser you will probably end up with a file called – if you use wget it will be called simply 6.x

Now unzip the file with, unsurprisingly, the unzip command:

This will create a directory called drush-6.x in your home directory. To make things easier, rename that directory to drush with:

And remove the zip file, as we don’t want it any more:

If everything has gone well you should now be able to type
ls -la drush and see the contents of the drush directory. You should see that the file called simply drush and drush.php have permissions -rwxr-xr-x as shown below

If not then run the command
chmod u+x drush/drush drush/drush.php to make sure that drush is runnable.

The next step is to make drush accessible no matter what directory we are working in. You can do this by editing the .bashrc (if it’s there) or .bash_profile using the command
nano .bashrc to add this line to the end.

then press Ctrl-X to exit nano, and press Y to confirm to save the changes. You can now type
source ~/.bashrc or
source ~/.bash_profile depending on which file you edited to add the alias to the active shell session.

You should now be able to type drush from the command prompt to see a list of drush commands! Success!

Things that can go wrong

1. Restrictive PHP environment

Didn’t work out so well? OK, you might see something like this

Many hosting companies disable a number of PHP functions, including exec() for security reasons. To fix this in a secure fashion, you should

  • get a copy of the server’s default php.ini file, located at /usr/local/lib/php.ini on most cpanel servers.
  • find the line with the disable_functions = directive and remove exec from the list of disabled function names.
  • save the modified php.ini file in your ~/drush directory.

2. Command line uses php-cgi

PHP has two binaries – one intended for web CGI use, and one intended for command line CLI use. Some hosts use the CGI version for command line environments. Drush is not compatible with the CGI binary, and will give an error including this text:

You can confirm if you are running the right binary by running
php -v and checking the output, which will include something like this for the (correct) cli binary. Note the (cli) after the php version.

If you are not running cli, then you need to find where the cli binary is – on a cPanel server it’s normally sym-linked from /usr/bin/php-cli. To ensure Drush uses the correct CLI binary add these lines to the end of the .bashrc or .bash_profile file instead of the alias command you previously put there:

Again, you should run
source ~/.bashrc or
source ~/.bash_profile to enable the aliases immediately, and try to run drush again.

And finally

This is an advanced topic intended for people with a keen interest in developing Drupal. The command line is not a place to experiment with Drush, especially in a production environment, so please beware!



One Response to Install Drush on cPanel shared hosting

  1. justin February 6, 2015 at 00:07 #

    Your guide has worked well for me thankyou. I have installed drush on a cpanel that will not dl drupal, if I run drush all is fine, drush status all is fine, ls -la drush all is fine. If I run drush dl drupal, I get unable to copy and unable to move both are errors.

    then it will say whats below but nothing is there, any suggestions i’m using putty?
    Project drupal (7.34) downloaded to /home/site/drupal-7.34. [success]
    Project drupal contains:

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.