Drupal 8: How to install Drush on shared hosting?

Drupal 8: How to install Drush on shared hosting?

Fri, 02/12/2016 - 21:49
Posted in:

Drupal + Shell = Drush is command line shell and scripting interface for Drupal CMS. I will show how to install Drush for Drupal 8 on shared hosting like Big rock and Godaddy.

When you purchase a shared hosting server for your website. You get the cPanel access. I am considering here that you have already got an cPanel access and if you don't then please contact support.

Log in to your cPanel hosting account via SSH. Make sure SSH is enabled for your IP before starting guide. You can access ssh by two ways by public key authentication and password authentication. Public key authentication is more secure.

Mac and linux users will achieve this using the terminal application built into the operating systems, and Windows users will use software like PuTTY.

So here are steps to install drush.

Step 1 : Obtaining the Drush files

Log in to your cPanel with SSH (Use cPanel username and password),

Once logged in, check if you are in the home directory of your hosting account i.e in home/<username>, where username is your primary username for cPanel. You can ensure this by using the command pwd to print your current directory. If you are not in home directory use command cd or cd ~

From your home directory, use the wget command to get the version of Drush which is compatible with latest drupal 8 version. Here is drupal compatibility table.

Drupal compatibility with Drush

We suggest getting this directly from Drush's master GitHub, to ensure that it is always the most up-to-date version of Drush for Drupal 8.

wget https://github.com/drush-ops/drush/archive/master.zip

You now have a .zip of the most up-to-date version of Drush, in your home directory.

Step 2 : Installing Drush files

Unzip the drush file archive and then delete old zip file by using the following command. Als

unzip -q master.zip && rm master.zip

This will extract all files to the ~/drush-master directory. For the ease of use, lets rename this directory to simply be 'drush', by using the following command:

mv ./drush-master ./drush

You should now have a directory in your home directory named "drush".

Step 3 : Add alias

Type command ls -a to get all list of files and folder in home directory. You can see .bashrc file.

Now we need to update .bashrc (or .bash_profile) file so that bash executable knows to recognize the alias 'drush'.

You can do it by adding the following line at the end of .bashrc file in your home directory.

alias drush='~/drush/drush'

This can be done by using text editor, such as Notepad++ or directly in SSH by using vim. If you have never edited your .bashrc file for any other reason, then you can simply add this line to the file by running the following command:

echo "alias drush='~/drush/drush'" >> .bashrc

Step 4 : Installing Composer

Composer manages the dependencies you require while using Drush. This means that Composer will pull in all the required libraries, dependencies and manage them all in one place. This section will show how to get Composer, then properly use composer to complete the install of drush.

Go to the drush directory by using the cd command.

cd drush

Use the curl command to grab the composer files, then pipe them to PHP to be executed. This is done by using the following command.

curl -sS https://getcomposer.org/installer | php

You should see an output regarding the settings of composer.

Run the command that composer provides to you to properly install Drush.

php composer.phar install

You will see an output of different dependencies that are installed for Drush. Composer should now complete the dependency installs for Drush

Step 5 : Finalising Drush setup

So all the important stuff is done now, we just need to do a couple last things, and confirm that Drush is now running.

Navigate back to your home directory. This is easily done with the command:

cd ~

Now that you are back in your home directory, you need to reset your bash settings for your user so that it takes the new alias that you previously added to your .bashrc file. This is easily done by running the following command:

source .bashrc

Now, lastly to confirm that drush is running, type the command:

drush core-status

You will get current version details.

You can check all commands list and their details on drushcommands.com.

Done! Drush is now installed on your shared hosting account. Now you can install, update and do lot of other things using Drush

Also check : How to update Drupal 8 core with help of drush?



Submitted by James Rome on Mon, 09/12/2016 - 19:31 Permalink

But the problem is that my command line php is 5.2, which is too old to run drush. They have 5.4 and 5.6 installed. How do I override their decision to use 5.2? I know where the newer versions are.

You have to make a change in Step 3 In .bashrc (or .bash_profile) file instead of adding 

alias drush='~/drush/drush'

Try adding

alias drush='/path-to-php ~/drush/drush'

where path-to-php is your path to php version you want to use.

I did that. But I still get an error when I try to run drush:
# drush

Warning: require(__DIR__~/drush/includes/preflight.inc): failed to open stream: No such file or directory in /home2/mysite/drush/drush.php on line 10

I have
alias drush="/ramdisk/php/54/bin/php54-cli ~/drush/drush"
alias php=/ramdisk/php/54/bin/php54-cli

Another page said to point to php54-cli. Not sure what the difference is between that and php54

I'm still getting: X-Powered-By: PHP/5.2.17 Content-type: text/html
Warning: include(__DIR__/includes/startup.inc) [function.include]: failed to open stream: No such file or directory in /home1/dpadiabl/drush/drush on line 113

Warning: include() [function.include]: Failed opening '__DIR__/includes/startup.inc' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /home1/dpadiabl/drush/drush on line 113

Fatal error: Call to undefined function drush_startup() in /home1/dpadiabl/drush/drush on line 115

Submitted by Anonymous on Fri, 07/28/2017 - 11:49 Permalink

+1 This worked for me on GoDaddy shared hosting.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The content of this field is kept private and will not be shown publicly.