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
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.
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.
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
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.
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.
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:
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:
Now, lastly to confirm that drush is running, type the command:
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