Skip to main content

Install Drupal 8 on Ubuntu 16.04 With Nginx, MariaDB and PHP7

install drupal 8 on ubuntu 16.04 (1)

If you want to know how to install Drupal 8 on Ubuntu 16.04 LTS with Nginx, MariaDB and PHP7, you have come to the right place.

WordPress is the most popular content management system (CMS) under the sun, loved by millions of bloggers and webmasters around the world thanks to its ease of use and thousands of plugins and themes. However, it’s also cumbersome and sluggish to advanced users who have better web skills than the average bear.

Drupal is another game in town. Drupal is faster, more secure and more SEO-friendly than WordPress. If you are tired of WordPress and don’t mind the low number of themes and modules (aka plugins) available for Drupal, then give Drupal a try.

So in this tutorial, I will show you how to install Drupal 8 on Ubuntu 16.04 LTS Xenial Xerus with Nginx, MariaDB and PHP7. I assume that you have already set up a LEMP stack on Ubuntu 16.04. If not so, click the link below to check out my easy-to-follow guide. Drupal also works with LAMP, but here I show you how to set it up with LEMP.

Install Nginx, MariaDB and PHP7 (LEMP Stack) on Ubuntu 16.04 LTS

When you are finished, come back here and read on.

Install Drupal 8 on Ubuntu 16.04

First, upgrade all your system software to the latest version available in your software repository using the following command:

sudo apt update && sudo apt upgrade

Next, download Drupal from the official website to your Ubuntu 16.04 server. You can use wget to do that. The latest stable version is Drupal 8.1.2 which is released on June 15, 2016.


When you read this tutorial, there may be a newer version of Drupal available, you can check it at

Once the download is completed, unpack it using the following command. This will create a drupal-8.1.3 directory under the current directory.

tar xzvf drupal-8.1.3.tar.gz

Now move all the files in drupal-8.1.3 directory to the web root. If you followed the previous LEMP tutorial, then your web root will be /usr/share/nginx/html.

sudo mv drupal-8.1.3/* /usr/share/nginx/html/

Create a Database and User for Drupal 8

Drupal is a content management system and as such it needs a database to store the content. Run the following command to log into MariaDB shell as root. Note that this is the MariaDB root user, not the root user of Ubuntu system.

mysql -u root -p

If you can’t log into MariaDB, then check out how to fix MariaDB plugin ‘unix_socket’ is not loaded error.

Once you are logged in,  create a new database for Drupal 8 using the following command. I name it drupal, you can use whatever name you like.

create database drupal;

Next, create a new database user on localhost using the following command. Again, I name it drupaluser, you can use whatever name you like.

create user drupaluser@localhost;

Set a password for the user. Replace your-password with your preferred password.

set password for drupaluser@localhost= password("your-password");

Then grant all permission of the new database to the new user:

grant all privileges on drupal.* to drupaluser@localhost identified by 'your-password';

Flush the privileges table:

flush privileges;

Exit MariaDB Shell:


Configuring Drupal

Change your working directory to the web root:

cd /usr/share/nginx/html

Copy the default settings to a new file:

sudo cp sites/default/default.settings.php sites/default/settings.php

Add write permission to settings.php file and sites/default directory

sudo chmod a+w sites/default/settings.php
sudo chmod a+w sites/default

Now we need to change the owner of web root directory to the Nginx user. The nginx user is usually nginx or www-data. You can check it in /etc/nginx/nginx.conf file.

sudo chown nginx:nginx /usr/share/nginx/html/ -R


sudo chown www-data:www-data /usr/share/nginx/html/ -R

Create a Nginx Config File for Your Drupal Site

sudo nano /etc/nginx/conf.d/drupal.conf

Put the following text into the file. Replace the red-colored text with your real domain.

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

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
  root /usr/share/nginx/html;

location ~ \..*/.*\.php$ {
  return 403;

# Block access to hidden directories
location ~ (^|/)\. {
  return 403;

location ~ ^/sites/.*/private/ {
  return 403;

# No php is touched for static content
location / {
  try_files $uri @rewrite;

# Clean URLs
location @rewrite {
  rewrite ^ /index.php;

# Image styles
location ~ ^/sites/.*/files/styles/ {
  try_files $uri @rewrite;

location = /favicon.ico {
  log_not_found off;
  access_log off;

location = /robots.txt {
  allow all;
  log_not_found off;
  access_log off;

location ~ \.php$ {
  try_files $uri =404;
  fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi_params;

Save and close this file. Then test Nginx configurations and reload Nginx.

sudo nginx -t

sudo systemctl reload nginx

Finish the Drupal installation in Your Browser

Make sure that your domain name is pointed to your Ubuntu 16.04 server in DNS. Then in your browser address bar, type


Replace with your real domain name. You will see the Drupal installation wizard, also know as Drupal installer. Follow the instructions to finish the Drupal 8 installation.

Install Drupal 8 on Ubuntu 16.04

If you can’t see the installation wizard, that’s probably because some PHP extensions such as php-curl, php-mbstringphp-gd are not enabled on your server.

Let’s go through the steps.

Choose language

The language you choose in the first step will be the language of Drupal structure and the Drupal backend. You can, however, write content in other languages. If you want to build a multilingual site with Drupal, the settings can be configured later on. For this tutorial, we choose English so that the administrator interface is in English.

Choose Profile

Step 2 is to choose an installation profile. If you are installing plain Drupal core, ie, not Drupal distributions, then you options will be standard and minimal. You want to choose standard if you are a Drupal beginner. You only want to choose minimal if you really are an advanced Drupal user who like to heavily customize the site that is going to be built.

install drupal 8 on Ubuntu 16.04 intallation profile

Verify Requirement

If you followed this tutorial step by step, the requirement should be verified successfully and you don’t have to do anything in this step.

Set up database

This step is to connect to the MariaDB database. So enter the database, database user and password you created earlier.

drupal 8 connect with mariadb database

Click Save and continue button, it will begin installing 40 core modules which comes with the standard installation profile. If you choose minimal profile, then a lot of core modules will not be installed.

install 40 drupal core modules

Configure Site

This is the last step. In the site information section, enter your preferred site name and site email address. The site email address is for automated emails to be sent to site users or site visitors for registration, password recovery or other stuff. It’s used to identify your site. You don’t want to enter your personal email address such as [email protected] Instead, enter an email address such as [email protected]

drupal site information

The site maintenance account is user 1 in a Drupal site. It’s like the root user on Linux who can do anything in the system including harmful things to the system. It is not best practice to use this site maintenance account to do normal stuff in a Drupal site. Choose a username other than admin or webmaster. These two username can be easily guessed. The email address is used when you forget the password of user 1. So enter an email address different from the site email address.

Drupal user 1 site maintenance account

Then select a default country and default time zone. The email notifications will be sent to the email address of user 1.

Remember that all of the above settings can be changed later on. Finally, click Save and continue. You will be taken to the home page of your Drupal site.

install Drupal 8 on Ubuntu 16.04

Congrats! You have successfully installed Drupal 8 on Ubuntu 16.04 and can now start building your Drupal site!

Comments, questions or suggestions are always welcome. If you found this post useful, 🙂  please share it with your friends on social media! Stay tuned for more Linux tutorials.

Rate this tutorial
[Total: 1 Average: 5]
  • Jordan

    The following is if you are trying to setup the database but cant login try the sequence below(trying to authenticate root using plugin not password. Below disables plugin for root)

    shell$ sudo mysql -u root

    [MariaDB] use mysql;
    [MariaDB] update user set plugin=” where User=’root’;
    [MariaDB] flush privileges;
    [MariaDB] q

    • Yes, this will disable the unix_socket authentication plugin for MariaDB root user and enable mysql_native_password for MariaDB root. Thanks for pointing this out !

  • Jordan

    If you are having problems creating a USER then jump back above and finish steps:

    [MariaDB] create user ‘drupaluser’;
    Query OK, 0 rows affected (0.00 sec)
    Query OK, 0 rows affected (0.00 sec)
    [MariaDB] set password for [email protected]= password(“your-password”);
    Query OK, 0 rows affected (0.00 sec)

  • Libertas

    Thanks for an excellent tutorial!

    (Please note: do NOT choose a language different from English, otherwise it finishes the installation with error 404)