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

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.3 which is released on June 15, 2016.

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

When you read this tutorial, there may be a newer version of Drupal available, you can check it at https://www.drupal.org/project/drupal. Simply replace 8.1.3 with the newer version number.

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:

exit;

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 u+w sites/default/settings.php
sudo chmod u+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

or

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;
  server_name www.your-domain.com your-domain.com;
  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

your-domain.com

or

your-domain.com/core/install.php

Replace your-domain.com 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. You can enable them with the following command:

sudo apt install php-curl php-mbstring php-gd

Now 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: 10 Average: 4.4]

18 Responses to “Install Drupal 8 on Ubuntu 16.04 With Nginx, MariaDB and PHP7

  • 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

    • Xiao Guo-An (Admin)
      9 years ago

      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 !

  • 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)
    [MariaDB] FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    [MariaDB] set password for drupaluser@localhost= password(“your-password”);
    Query OK, 0 rows affected (0.00 sec)

  • Libertas
    8 years ago

    Thanks for an excellent tutorial!

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

  • I used this tutorial, but when I finished installation, every link I try to click on gives me a 404 Not Found error.

    • Xiao Guoan
      8 years ago

      Hi, I tested this tutorial again and selected English as the language. It worked for me without any problem. Which language did you choose?

      • English. I’m not installing this on a remote server though. Here’s my setup, in my home I have a Dell PowerEdge R610 running XenServer 7.0 that has multiple VMs installed. Right now I have an Ubuntu Linux server 16.04.1 LTS running. I installed PHP 7, Nginx, and MariaDB. On my workstation, when I put in the local IP of that VM, it takes me to the Drupal home page, but I get 404 errors on every single link.

        • Xiao Guoan
          8 years ago

          In that case, it’s a good idea to check out Nginx error log at /var/log/nginx/error.log.

        • No errors in the log, just notices that the signal process was started.

        • Xiao Guo-An (Admin)
          8 years ago

          I also did a test on my local Ubuntu 16.04 box. No issues at all.

        • I spun up another VM and followed the LinuxBabe tutorial for LEMP stack, then tried to install WordPress 4.6 using that tutorial. I end up with the same problem. I get a 404 error when I type /wp-admin/install.php.

          Is this a permissions issue or am I not pointing to the right directories somehow? This doesn’t make any sense to me.

          I also installed Ubuntu Desktop using sudo apt-get install ubuntu-desktop on the VM I did this Drupal 8 tutorial on. When I go to the Console tab in XenCenter, log onto the server using the graphic Unity interface, and open up Firefox, type localhost in the address bar, I get the “Welcome to nginx” page. However when I type the actual VM’s IP address, I get the Drupal site, but I still suffer from 404 errors.

        • Xiao Guoan
          8 years ago

          It could be that the Nginx server block config file is not pointing to the right web root directory. This tutorial sets /usr/share/nginx/html/ as the web root. In the WordPress 4.6 tutorial, it’s /usr/share/nginx/you-site.com.

          Permission issue can be easily resolved by assigning nginx user as the owner.

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

          By default, the nginx username is www-data. Sometimes it could be nginx. You can check out the user directive in /etc/nginx/nginx.conf to see which is the right one.

          As always, the Nginx error log can be of help.

        • Here’s the Nginx error log.

          2016/09/02 03:33:14 [notice] 5710#5710: signal process started
          2016/09/02 03:33:43 [notice] 5832#5832: signal process started

        • Xiao Guoan
          8 years ago

          Try reloading or restarting Nginx.

          sudo systemctl reload nginx

          sudo systemctl restart nginx

          Also test Nginx configuration to see if any config errors exist

          sudo nginx -t

        • None of that worked, but here’s what did.

          In your LEMP stack tutorial and this tutorial, every time I saw “/usr/share/nginx/html/”, I replaced it with “/var/www/html/”. I un-tarred the files into /var/www/html/ on a clean LEMP stack install.

          Both the WordPress 4.6 install and the Drupal 8.1.8 install now work.

          I cannot figure out why it works if I do this, but it works.

        • David
          6 months ago

          Might be that /etc/nginx/sites-available/default has root /var/www/html instead of /usr/share/nginx/html. When symlinked to /etc/nginx/sites-enabled nginx will read the /etc/nginx/sites-available/default file. If having this trouble, look at the root file locations for the target server_names.

  • Warner Veltman
    8 years ago

    Great tutorial, thanks for the hard work!

    However, I seem to have pretty much the same issue as Rath below: the install of Drupal completes without errors, but apart from the basic page (which works just fine), every link results in 404.

    I have tried many things, but no solution yet. The /sites/default/files/php/twig folder is empty though – which makes me think it is an config issue.

    Also here, English as language. 16.04 box (no VM) and the web address in /etc/nginx/conf.d/default.conf is just 192.168.x.x.

    Any hint where to look? Is there a config file for PHP that is still pointing to another (apache default?) location? The only thing I haven’t tried is changing the folder from /usr/share/nginx to /var/www/html/ (which was the solution for Rath). Guess I’m still hoping to find the right config file.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here