How to Install Drupal with Nginx on an Ubuntu 13.04 VPS


Drupal is a free open source content management framework based on PHP, distributed under GNU general public license. It can run on any computing platform that supports web server capable of running PHP, Apache or Nginx and a database such as MySQL to store content and settings.

Community contributed add-ons and modules extend Drupal’s core capabilities and make it customizable with behavior and appearance.


System Prerequisites

This tutorial covers the basics of installing Drupal with Nginx on Ubuntu 13.04.

This will require you:

  • Ubuntu 13.04 VPS
  • User with root privileges on VPS. Check server set up tutorial for guidance.
  • LEMP stack (Linux, Nginx, MySQL and PHP) should be installed on your cloud server. Check this tutorial for more information on LEMP stack set up.

Now that you have all the require components, we shall begin installation of Drupal.


Download Drupal

You can download the latest version of Drupal from their Drupal website using the command:


Unzip the downloaded Drupal file to your home directory:

tar xzvf drupal-7.23.tar.gz

You can locate the unzipped files in drupal-7.23 folder.


Creating a Drupal Database and User

In this step we will be creating a new MySQL database for Drupal. Also, we will have to create a user too.

Login to the MySQL shell using the command:

mysql -u root -p

Enter the MySQL root password and it will drop you in MySQL shell.

Now, create a database for Drupal using the following command:

Query OK, 1 row affected (0.00 sec)

I have used the name ‘drupal’ for the database. You may wish to replace it with your choice.


Now, let’s create a new user:

CREATE USER [email protected];
Query OK, 0 rows affected (0.02 sec)

I have given the name drupaluser for simplicity. Replace it according to your requirement.

You can set the password for the new user using the command:

SET PASSWORD FOR [email protected]= PASSWORD("password");

Now that we have created a user and set password, we can proceed to granting permissions for the user. This step is very important.


GRANT ALL PRIVILEGES ON drupal.* TO [email protected] IDENTIFIED BY 'password';

Refresh MySQL using:


Exit from the MySQL shell:



Copying the Files


We need to create a new directory for Drupal inside the default server directory. Default server directory in Ubuntu 13.04 is /usr/share/nginx/html/.

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

You should copy the drupal files to your server directory from home.

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


Configure Drupal

Make a copy of the default configuration file and make it writable by changing permissions:

sudo cp 

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

You should also change the permissions of the settings directory as well:

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

Drupal installation would require a specific php module to be downloaded and installed. We will be doing it with the command:

sudo apt-get install php5-gd

Now that you have it installed, restart the php5-fpm service using:

sudo service php5-fpm restart


Configure Nginx

Here, we will be setting up a Drupal virtual host for nginx.

Copy the default host for Drupal:

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

Open up the nginx virtual host:

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

Make the following changes to the configuration:

  1. Change the root user to  /usr/share/nginx/html/drupal.
  2. Change the server_name. Replace localhost with your domain name or IP address.
  3. Enable the Drupal Permalinks with Nginx. For that, change the line “tryfiles $uri $uri/ /index.html;”  to  “tryfiles $uri $uri/ /index.php?q=$uri&$args;”

Once you are done with the configuration changes, it should look like this:

server {        
listen   80;        
root /usr/share/nginx/html/drupal;        
index index.php index.html index.htm;        
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$        location ~ \.php$ { 
               # With php5-fpm:     
               fastcgi_pass unix:/var/run/php5-fpm.sock;                             
               fastcgi_index index.php;    
              include fastcgi_params;       


Activate the Configuration

You can enable the Drupal configuration using:

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

Remove the default configuration:

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

Restart Nginx:

sudo service nginx restart


Online Installation

Open up your browser and point it to your IP address or domain followed by ‘/drupal’. You will be taken to a page where you can proceed with the online installation process.

support2 has written 111 articles

Leave a Reply