Installing Drush on Hostgator shared hosting
Ok I'll admit I've been a bad Drupalista. I've just gotten around to installing Drush and figuring out how to use it. Hey, what do they always say? Better late than never, right? Well today I made it my goal to figure out this Drush stuff and seeing the sad lack of instructions on how to get the thing up and running I thought I'd write my own tutorial for others out there using HostGator or other shared hosting.
Here's my process, step by step:
1. First and foremost, you're going to need SSH access to your webserver. For Hostgator enabling this is really easy. You just need to go to your HostGator Billing Account located at http://gbclient.hostgator.com. Login and navigate to View Hosting Packages under Hosting Packages on the left sidebar.
Once there click on Enable Shell Access.
For additional documentation on how to do this step visit the Hostgator support page at http://support.hostgator.com/articles/getting-started/how-do-i-get-and-use-ssh-access.
2. Now to make use of our Shell access we'll need to download a program called PuTTY. There are other programs you can use as well, like WinSCP, but I used PuTTY. Download PuTTY here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html I just downloaded the first putty.exe link under For Windows on Intel x86 If you're on a different operating system use the link that makes sense for your situation.
Connecting to your Server
3. Once PuTTY is installed, open it up. You'll need to find your HostGator IP address which you can see if you log in to your Cpanel and look in the bottom of the left sidebar. Type your ip address in the text box that says Host Name (or IP Address) and then change the port number from 22 to 2222. Now click the Open Button.
Working from the Command Prompt
4. You'll now be presented with a command prompt. First thing to do is login with your cPanel username and then your password.
(note: from here on I mostly followed the instructions found here, but have modified them slightly to work with HostGator.)
6. Now we actually need to download drush to our web server. You can do this easily by using the wget command. First go to http://drupal.org/project/drush and grab the link to the latest release of drush. For example I used the url http://ftp.drupal.org/files/projects/drush-7.x-4.3.tar.gz. Then type this into the command prompt:
7. Now we need to unpack the file to /public_html/drush. To do this type this:
tar –xf drush-7.x-4.3.tar.gz Make sure to use the version numbers for whatever link your grabbed in case it's different from the version I'm writing this tutorial on.
Setting up Drush
8. Technically Drush is now installed, but we need to do a little configuring before we can really use it. First let's go into our drush folder by typing:
Something called Aliasing
10. So now we need to do something called aliasing, basically this will allow us to type in
drush commands no matter where we are in our file structure and the command prompt will know to go back to our drush folder to process our commands. Something like that. Basically if you try typing the command
drush status right now you won't get anything. To alias this thing we need to open up a file and make some edits to it. All this is going to take place within the command prompt. Yes, you can edit files in here too :) Type
cd ~/ to take us back to our root. Now we want to list all the files in there so type
ls -a. You'll see a bunch of files in there, the one we're looking for is .bashrc. To open that file type
11. Navigate your cursor to the end of the line that reads # User specific aliases and functions. Now press
i on your keyboard. When you press
i you should see the bottom left off your screen say INSERT. Now we can make edits to this file. Hit Enter on your keyboard to go to the next line and start typing. First we're going to type this:
12. Now hit enter and type this:
alias drush='/usr/bin/php ~/public_html/drush/drush.php'
Don't forget the ending ' at the end of that line. I did the first time and the whole thing froze up on me.
13. Now type this on a new line:
And that's it. Hit Esc on your keyboard to leave INSERT mode. Now we need to "save" this file. To do that type
:w and hit enter. This will write our changes to the file. Next type
:q to exit this screen and return to our normal command prompt.
14. Now we need to logout and log back in. To do this type
logout. Your command prompt will disappear.
15. Open up PuTTY and reconnect to your server.
16. Type the command
drush. This should show you a list of different commands that you can use. If this works then you have successfully installed drush on your HostGator web server. CONGRATS!