How to Install Drupal 9 on Ubuntu 20.04

In this article, we’ll explain how to install Drupal 9 on Ubuntu 20.04. The tutorial will guide you to install and configure Nginx as web server, PHP, MariaDB as a database.

Drupal is a free and open-source content management system. With robust content management tools, sophisticated APIs for multichannel publishing, and a track record of continuous innovation—Drupal is ready to stand as the hub of your digital presence.

Install Drupal 9 on Ubuntu 20.04


1. Keep the server up-to-date:

# apt update -y

# apt upgrade -y

2. Install Nginx

# apt install nginx -y

Start and enable nginx.service using following command:

# systemctl start nginx && systemctl enable nginx

In case, you enabled UFW firewall and firewall block requests of the apache web server, open a port in the firewall.

# ufw allow 80/tcp

# ufw allow 443/tcp

# ufw reload

Now, let’s verify the Apache installation. Open browser and test default page.

http://[SERVER IP]

3. Install MariaDB

We need to import the public key used by the package management system. We can import it using following command:

# apt-key adv –fetch-keys ‘’

Add repository

# add-apt-repository ‘deb [arch=amd64,arm64,ppc64el] focal main’

Once the key is imported and the repository added you can install MariaDB 10.5 from the MariaDB repository with:

# apt update -y

# apt install mariadb-server -y

Start and enable the mariadb.service using following command:

# systemctl start mariadb && systemctl enable mariadb

Login into mysql and create a database and user.

# mysql

If you have set root password:

# mysql -u root -p

First, we can create a separate database that Drupal can control.

We can create the database for Drupal by typing:

mysql> CREATE DATABASE drupal DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

You can replace and call drupal whatever you like.

Now, create a user and grant the permision of the database we have created eariler.

mysql> GRANT ALL ON drupal.* TO ‘drupaluser’@’localhost’ IDENTIFIED BY ‘password’;

Resplace drupaluser to your username and set password with strong password.

To refect the change run following command:


Once everything done, EXIT the mysql.

4. Install PHP and configure

# apt install php-fpm php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

Verify the PHP installation:

# php -v

Open php.ini file and look for the parameter that sets cgi.fix_pathinfo. We will be uncommented by removing semi-colon(;) and set to 0.

# vi /etc/php/7.4/fpm/php.ini


Once you have done, save and exit.

Next, restart php-fpm service:

# systemctl restart php7.4-fpm

Configure Nginx server block to use PHP Processor. Here we are using default server block. If you want, you can create new server block.

# vi /etc/nginx/sites-available/default

  • Here we need to add an index.php index directive to allow PHP files to be served when a directory is requested.
  • Modify the server_name directive. Replace localhost with your FQDN domain name or public IP address.
  • Add a try_files directive to make sure Nginx doesn’t pass bad requests to our PHP processor.

The server block should looks like:

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

root /var/www/html;

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

server_name server_domain_name_or_IP;

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;


Replace the server_domain_name_or_IP to your server IP or website name.

Test the configuration file.

# nginx -t

If there are no errors, restart the Nginx to make the necessary changes.

# systemctl restart nginx

5. Download Drupal

Now, we can download latest version of the Drupal from here. Use /tmp directory to download and extract Drupal.

# cd /tmp

# wget

Extract the compressed file to create the Drupal directory structure:

# unzip drupal-*.zip

# cd drupal-9.1.4

Move all the files into our root directory using following command:

# mv * /var/www/html

Next, change the default.settings.php config file name to settings.php.

# cd /var/www/html/sites/default

# cp default.settings.php settings.php

6. Access the Drupal

Finally, navigate to the browser and enter your domain name or IP address of the server. Go with the startup wizard. Once the configuration gets complete, you can access the Drupal control panel.

Install Drupal 9 on Ubuntu 20.04

The installation has been completed successfully.

In this tutorial we have seen how to install Drupal 9 on Ubuntu 20.04.

Related Articles