Install Drupal 7 on Ubuntu 16.04 With NGINX

Leave your reply

Introduction

Drupal is a popular blogging and CMS platform. It works well when combined with NGINX, a web server which is designed to be easy to use and to deliver high performance. Learn how to install and run Drupal on NGINX.

Requirements

  • A server running Ubuntu 16.04
  • Familiarity with basic Drupal functionality.
  • NGINX installed and running.

For more information on installing and running NGINX, see our article on the subject.

Note: For any server with Plesk, applications like Drupal should always be installed and managed through the Plesk interface. See our article Use Drupal on a Server with Plesk for step-by-step instructions.

Install the Prerequisites

In order to run Drupal, first update the server's packages:

sudo apt-get update

Next, install a collection of PHP tools with the command:

sudo apt-get install php7.0-fpm php7.0-cli php7.0-gd php7.0-mysql php7.0-xml php7.0-mbstring

After the installation is complete, restart NGINX with the command:

sudo systemctl restart nginx

Then restart PHP-FPM with the command:

sudo systemctl restart php7.0-fpm
sudo nano /etc/nginx/sites-available/example.com.conf 

Locate the line which reads:

index index.html index.htm;

Add index.php to this line (if it is not already there) so that the line reads:

 index index.php index.html index.htm;

Next, you will need to enable the various PHP configurations.

Uncomment these lines (if the configuration file was copied from the default) or add the following code to the server block:

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

For example, if your configuration file looks like this:

server {
    listen       80;
    server_name  example.com;
    root /usr/share/nginx/example.com/html/;
    index index.php index.html index.htm;
}

After adding the new section, it will look like this:

server {
    listen       80;
    server_name  example.com;
    root /usr/share/nginx/example.com/html/;
    index index.php index.html index.htm;

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

}

Save and exit the file, then reload the NGINX configurations:

nginx -s reload

Download and Unpack the Drupal Software

Connect to your server using SSH, and go to your website's document root. Under NGINX, the default document root is /usr/share/nginx/html:

cd /usr/share/nginx/html 

Download the current release from the Drupal website by using the command:

sudo wget [download URL]

To find the download URL, visit the current release page on the Drupal website. Go to the "Recommended release" for Drupal Core 7.x.

On the next page, copy the "Download .tar.gz" link. To do this, right click on the download button and choose "Copy link location." You can then paste this URL into the command line by clicking Shift + Insert.

For example, to download the current stable release of Drupal 7 as of this article's publication (Drupal 7.50) the command is:

sudo wget https://ftp.drupal.org/files/projects/drupal-7.50.tar.gz

Unpack this file using the command:

sudo tar --strip-components=1 -xvzf [file name]

Tip: You can use tab completion to make this process easier. Type sudo tar -xvf drup then hit Tab. The shell will automatically fill out the rest of the file name on the command line.

For example, to unzip the file downloaded above, the command is:

sudo tar --strip-components=1 -xvzf drupal-7.50.tar.gz

After the contents of the Drupal file have been unpacked, set the ownership of the files to the NGINX user:

sudo chown -R www-data:www-data *

And set the permissions:

sudo chmod -R 755 *

You can now delete the .tar.gz file:

sudo rm [file name]

In this example, the command is:

sudo rm drupal-7.50.tar.gz

Create the Database

Next, you will need to create a database. Connect via SSH to your server and log in to MySQL/MariaDB with the command:

sudo mysql –u root –p

After you enter the MySQL/MariaDB root user password, you will be logged into the MySQL/MariaDB client.

Create a database with the command:

CREATE DATABASE [database name];

Replace [database name] with the name you want to use for your new database. For example, if you wanted to name your database my_drupal_site the command would be:

CREATE DATABASE my_drupal_site;

Create a user for this database and grant all privileges with the command:

GRANT all ON [database name].* TO [database username]@localhost IDENTIFIED BY '[database user password]';

Replace:

  • [database name] with the name of your database.
  • [database username] with the username you want to create for your database.
  • [database user password] with a password for this user. Note: Be sure to give the user a strong password.

For example, to create a user named my_drupal_user with the password Fr4i*Re!2 and give the user privileges on the my_drupal_site database, the command would be:

Once you have finished, exit the database with the command:

quit;

Complete the Installation

Next, switch to a browser and go to your website. You will see the Drupal installation page. Select Standard then click Save and Continue.

Install Drupal: Installation Page

On the next page, click Save and Continue.

Install Drupal: Installation Page
Install Drupal: Installation Page

On the next page, you will be asked to fill in some website details and create a Drupal Site Maintenance (admin) account. Fill out all the required fields, then scroll down and click Save and Continue.

Install Drupal: Installation Page
Install Drupal: Installation Page