This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
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:
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.
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
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!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Drush is a command-line interface specifically made for working with Drupal. It provides a much faster management experience and is recommended if you are comfortable with using the command line.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Click below to sign up and get $200 of credit to try our products over 60 days!
If you want to save time on server configuration for Drupal, you might want to look at Wodby. It’s integrated with DigitalOcean, just connect your DO account and create/import application in one click.
We should use composer instead of PEAR:
There is something missing that even the mod-rewrite is up and running and default folder has its permissions clean url’s are troubling…
I had to add “–clean-url=0” to the site install command to make it work properly. Otherwise it just says the node is not found… Maybe it’s related with the order of tasks IDK.
@pantasiov7: @craig.vanderlinden: Check out <a href=“https://www.digitalocean.com/community/questions/getting-errors-while-installing-drush-using-pear-command”>https://www.digitalocean.com/community/questions/getting-errors-while-installing-drush-using-pear-command</a>.
Same problem as pantasiov7
after command: pear install drush/drush PHP Fatal error: Cannot use string offset as an array in /usr/share/php/PEAR/REST/10.php on line 352 How I fix it
@Dan: You do not need to run the commands through sudo if you are running them as root (which is the default for a new droplet).
If you’re logged in as a regular user, just prefix the commands with "sudo " :]
Lots of sudo missing from this article.
@Arvind: Try logging out and logging back in, does that fix it? Did you follow Step 1?
After logging out of Mysql I navigated to /var/www and tried to execute the drush command but it came back with an error -bash: drush: command not found. What can I do to move forward?