How To Install Drush on a Cloud Server Running Ubuntu 12.04
Drush is a command-line interface specifically made for dealing with Drupal. It provides a much faster management experience and is recommended if you are not afraid of using the command line. But don't worry, it's actually not so threatening at all.
This tutorial will show you how to setup Drush on a cloud server running Ubuntu 12.04. Additionally, to illustrate its power, it will show you how to deploy a brand new Drupal site right there from the command line. For this, it assumes two things:
- You already have your cloud server set up and you operate with root privileges on it.
- You already have installed the LAMP stack (Linux, Apache, MySQL and PHP) on it.
Step 1: Installing Drush
There are 2 ways of installing Drush: using the drush pear channel or using apt-get. Using the second option is not sure to install the latest version of Drush, so I will show you how to do it via the pear channel.
First, install pear if you don't already have it:
sudo apt-get install php-pear
Next, install Drush:
pear channel-discover pear.drush.org
pear install drush/drush
You can then check if it successfully installed using the version command:
And you can update Drush by using the following command:
pear upgrade drush/drush
If you get "Nothing to upgrade", it means you are using the latest version.
Step 2: Installing Server Requirements for Drupal
In order for Drupal to work as you'd expect, you need to have a couple of things installed on your cloud server. First, you need the PHP-GD Graphics Library. You can quickly install it with the following command:
apt-get install php5-gd
Next, if this is not the case for you, edit the Apache default virtual host file and make sure that Allow Overrides is set to All under the /var/www directory. Edit the file with the following command:
And where you see this block, make the changes to correspond to the following.
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
This will make sure that the Drupal .htaccess file can override the default Apache instructions.
Finally, make sure that mod_rewrite is enabled in your Apache. You'll need this for the Clean URLs. To check if it is already enabled, use the following command:
If you see "rewrite_module" in the list, you are fine. If not, use the following command to enable the module:
After all these steps, or after any individual one you had to perform, give Apache a restart so they take effect:
sudo service apache2 restart
Step 3: Deploying a new Drupal site with Drush
Before installing a new Drupal site, you need to have an empty database, so use either phpmyadmin or the command line to set up a database. And make a note of the username and password for accessing it.
The following steps can help you set up the database in MySQL.
Go ahead and log into the MySQL Shell:
mysql -u root -p
Login using your MySQL root password. We then need to create a Drupal database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon.
First, let's make the database (I'm calling mine Drupal for simplicity's sake—for a real cloud server, however, this name is not very secure). Feel free to give it whatever name you choose:
CREATE DATABASE drupal; Query OK, 1 row affected (0.00 sec)
Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:
CREATE USER druser@localhost; Query OK, 0 rows affected (0.00 sec)
Set the password for your new user:
SET PASSWORD FOR druser@localhost= PASSWORD("password"); Query OK, 0 rows affected (0.00 sec)
Finish up by granting all privileges to the new user. Without this command, the Drupal installer will be able to harness the new mysql user to create the required tables:
GRANT ALL PRIVILEGES ON drupal.* TO druser@localhost IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec)
Then refresh MySQL:
FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
Exit out of the MySQL shell:
Now that you have a database set up, you can install Drupal. Navigate to your main www folder (or wherever you'd like Drupal to be downloaded to):
Please note that with the following command, Drupal will be downloaded into a new folder with the name of your choosing so you don't need to create one yourself (but replace "folder_name" with the name you want). And now, you can download it:
drush dl drupal --drupal-project-rename=folder_name
Next, navigate inside the folder:
Then run the following install command but change some of the parameters to match your situation.
drush site-install standard --db-url=mysql://user:pass@localhost/db_name --site-name=your_site_name --account-name=admin --account-pass=your_password
Let's break down this command and its parameters. After the regular drush segment, you have the site-install standard part which makes it install the standard profile. Next you have the --db-url parameter which should contain the information about the database you set up for this site. The last three parameters reflect some basic information about the site: the site name, the user/1 account name and the user/1 account password. For more information on this command, check out the Drush specs.
Now your Drupal site is installed, but you need to make some folder permission changes for it to be able to work properly.
First, assign the sites/default/files (and everything inside) group ownership to the www-data group:
chown -R root:www-data sites/default/files
This will make the owners of the folder the root user and the www-data group. Note that Apache operates on your site as the www-data user which is part of the www-data group. Next, make sure that also the www-data group can write in that folder:
chmod -R 775 sites/default/files
And that's it. You are now set up with a new Drupal install!