We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install Drupal with Nginx on an Ubuntu 13.04 VPS

PostedOctober 16, 2013 33.1k views Nginx Drupal Ubuntu

Introduction

Drupal is a free and open-source content management framework (CMF) written in PHP and distributed under the GNU General Public License. It is used as a back-end system for at least 2.1% of all websites worldwide. As of August 2013, there are more than 22,900 free community-contributed add-ons, known as contributed modules, available to alter and extend Drupal's core capabilities and add new features or customize Drupal's behavior and appearance.

Initial Setup

In this tutorial, we will be using an Ubuntu 13.04 VPS. The following instructions require the user to have root privileges on your virtual private server. You can see how to set that up here (steps 3 and 4).

In order to work with Drupal, you need to have LEMP installed on your VPS. If you don't have the Linux, Nginx, MySQL, PHP stack on your cloud server, you can find the tutorial for setting it up here.

Only once you have the user and required software should you proceed to install Drupal.

1) Download Drupal

Download the latest version of Drupal from the Drupal website by using this command.

wget http://ftp.drupal.org/files/projects/drupal-7.23.tar.gz

Unzip the downloaded Drupal file in your home directory:

tar xzvf drupal-7.23.tar.gz

Now the Unzipped files will be in the folder drupal-7.23.

2) Create Drupal Database and User

Now we want to create a new MySQL database for Drupal. Login into your MySQL shell by using the command:

mysql -u root -p

Then enter your MySQL root password, which will drop you in the MySQL Shell. Don’t forget to add semicolons to end of MySQL querys.

Now let's create a database for Drupal by using this query. Here I am naming the Database drupal-- you may give it any name you like.

CREATE DATABASE drupal;
Query OK, 1 row affected (0.00 sec)

At this point, we need to create the new user. You can use any name:

CREATE USER drupaluser@localhost;
Query OK, 0 rows affected (0.02 sec)

Set the password for your new user:

SET PASSWORD FOR drupaluser@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)

Now we want to grant all permissions to the created drupal user. Without this we cannot proceed:

GRANT ALL PRIVILEGES ON drupal.* TO drupaluser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Refresh MySQL:

FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Finally, exit from the MySQL Shell:

exit

3) Copying the files

The default server directory in Ubuntu 13.04 is `/usr/share/nginx/html/`.

Create a new directory drupal in "/usr/share/nginx/html/":

sudo mkdir /usr/share/nginx/html/drupal

Copy the drupal files to your server directory from home:

cd ~
sudo mv drupal-7.23/* /usr/share/nginx/html/drupal/

4) Configuring Drupal

Copy the default configuration as settings.php:

sudo cp /usr/share/nginx/html/drupal/sites/default/default.settings.php /usr/share/nginx/html/drupal/sites/default/settings.php

Now make the settings.php file writable by changing the permissions:

sudo chmod a+w /usr/share/nginx/html/drupal/sites/default/settings.php

Change permissions for the settings directory:

sudo chmod a+w /usr/share/nginx/html/drupal/sites/default

We need a specific php module to proceed with Drupal installation. Download and install by using this command:

sudo apt-get install php5-gd

After it is installed, you will need to restart the php5-fpm service:

sudo service php5-fpm restart

5) Configuring Nginx

We need to setup Drupal virtual host for nginx. Copy the default host for Drupal:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/drupal

Open the nginx virtual host for Drupal.

sudo nano /etc/nginx/sites-available/drupal

The configuration should include the changes as below.

server {
        listen   80;
        root /usr/share/nginx/html/drupal;
        index index.php index.html index.htm;
        server_name 162.243.9.129;
        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/html/drupal;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
        location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

                 }

Here are the Changes:

  1. Change the root to /usr/share/nginx/html/drupal.
  2. Change the server_name from localhost to your domain name or IP address.
  3. Change the "try_files $uri $uri/ /index.html;" line to "try_files $uri $uri/ /index.php?q=$uri&$args;" in order to enable Drupal Permalinks with nginx.

Step Six - Activate the Configuration

Next enable the Drupal configuration:

sudo ln -s /etc/nginx/sites-available/drupal /etc/nginx/sites-enabled/drupal

And remove the default configuration:

sudo rm /etc/nginx/sites-enabled/default

Restart nginx:

sudo service nginx restart

7) Installation

Now open the IP address or domain in your browser followed by "/drupal" and continue the installation.

Submitted by: Raj Amal

17 Comments

Creative Commons License