How To Install Drupal CMS using Nginx on Ubuntu 20.04

Drupal is a dedicated CMS platform. It is written in PHP and is open source. This CMS is very popular and has many free templates and plugins. In this article, you will learn how to install Drupal 9 with Nginx on Ubuntu 20.04.

On the Hostry website, in the services section, you can select a server with LAMP already installed, you will not need to additionally install it.

Once you have selected this option, you will need to configure a few things to get Drupal up and running.

Configuring Nginx for this CMS

The first step is to make changes to your default Nginx server configuration block to use the PHP processor. This is because we will be using the IP address to access the portal:

nano /etc/nginx/sites-available/default

You need to replace the entire contents of the file with the text shown below. Then change the IP address of the example ( to the IP address of your server.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/drupal;

    index index.html index.htm index.nginx-debian.html index.php;


    location / {
        try_files $uri $uri/ /index.php$is_args$args;

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }
    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
        expires max;
        log_not_found off;

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

Then, after a successful change, you can try testing:

nginx -t

Restart your Nginx so that all changes are successfully updated

systemctl restart nginx

Configuring MariaDB for Drupal

First you need to log into MariaDB


Create a database named


Then you need to grant privileges to the drupal database

GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'StrongPassword';

Then you need to update for the changes to take effect:


The last step is to log out of MariaDB


Installing Drupal

If you don’t have unzip installed yet, you can install it as follows:

apt install unzip

Download the latest version of Drupal from the Drupal download page

Extract the compressed file and browse to it.

cd drupal-9.1.4

Create directory /var/www/html/drupal

mkdir /var/www/html/drupal

Move all files in the current directory to /var/www/html/drupal directory

mv * /var/www/html/drupal

Go to var/www/html/drupal/sites/default directory and copy the default.settings.php config file to settings.php

cd /var/www/html/drupal/sites/default
cp default.settings.php settings.php

Set the ownership of the drupal directory for the current user and group

chown -R www-data:www-data /var/www/html/drupal/
chmod -R 755 /var/www/html/drupal/

Access the Drupal page through a browser using your IP address. For example:

Was this article helpful?

Related Articles

Leave A Comment?