How To Install Drupal 9 On Ubuntu 20.04 LTS

On this short tutorial we will learn how to install Drupal 9 on Ubuntu 20.04 Sever.

Introduction

Drupal is an open source software based on PHP that, by working on the server side, allows the creation of dynamic websites, even quite complex ones. It is a free, modular and highly customizable CMS (Content Management System), and bea valid alternative to more popular tools such as WordPress or Joomla.  In this tutorial you will see all the steps to correctly install Drupal 8 (version 8.4.5) on your Cloud Server with Linux Ubuntu 20.04.

Drupal 9 is the latest release of the popular Drupal content management system (CMS). Drupal is a community driven platform for building amazing digital experience. It enables content creators to add, edit, publish, or remove content from a website, using a web browser on a smartphone, tablet, or desktop computer. This short tutorial will show you how to easily install and configure Drupal CMS on Ubuntu 20.04.

Drupal 9 System Requirements

  • Database server requirements.
    Drupal 9 requires MariaDB 10.3+ or MySQL/Percona 5.7.8+,PostgreSQL 10.0 or higher, SQLite 3.26 or higher
  • Web server requirements.
    Drupal works on Apache, Nginx, and other web servers. Drupal 9 requires at least Apache 2.4.7. Drupal will work on Nginx legacy versions (0.7.x, 0.8.x, 1.0.x, 1.2.x), stable 1.8.x versions, and mainline 1.9.x versions hosted on UNIX/Linux, OS X, or Windows.
  • PHP requirements.
    PHP version 7.4 or higher for current release versions of Drupal 9.

Drupal Installation On Ubuntu 20.04 Server

The installation process will be consist of several steps as shown below :

  1. Update system
  2. Installing Apache2
  3. Installing MariaDB
  4. Installing PHP 7.4
  5. Installing and Configuring Drupal 9
  6. Setting Up Drupal 9 Database
  7. Installing And Configuring Drupal 9

Each of the above steps will be detailed in the sub-chapters below.

1. Update System

By updating our Ubuntu system, it will refresh the local list of available packages software to the newer stable version. To update Ubuntu 20.04 LTS repositories, we will use the command line below.

$ sudo apt update

Output :

ramansah@app01:~$ sudo apt update
[sudo] password for ramansah: 
Hit:2 http://us.archive.ubuntu.com/ubuntu focal InRelease 
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] 
Hit:1 https://packages.cloud.google.com/apt kubernetes-xenial InRelease 
Get:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] 
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [29.0 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] 
Get:7 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [63.6 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,302 kB] 
Get:10 http://us.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [553 kB] 
Get:11 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [283 kB] 
Get:12 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [866 kB] 
Get:13 http://us.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [643 kB] 
Get:14 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [363 kB] 
Get:15 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B] 
Get:16 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [10.4 kB] 
Fetched 4,444 kB in 23s (194 kB/s) 
Reading package lists... Done
Building dependency tree 
Reading state information... Done

2. Installing Apache 2

Apache is used as a web server, where Drupal CMS will be hosted. Here are the steps for installing Apache 2.

2.1. Installing Apache 2

In this stage, we will nstall Apache 2 webserver by submitting command line :

$ sudo apt install apache2 -y

Output :

ramansah@app01:~$ sudo apt install apache2 -y
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
liblua5.2-0
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
liblua5.2-0
0 upgraded, 9 newly installed, 0 to remove and 353 not upgraded.
Need to get 1,820 kB of archives.
After this operation, 7,945 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libapr1 amd64 1.6.5-1ubuntu1 [91.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1 amd64 1.6.1-4ubuntu2 [84.7 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-4ubuntu2 [10.5 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu focal/main amd64 libaprutil1-ldap amd64 1.6.1-4ubuntu2 [8,736 B]
Get:5 http://us.archive.ubuntu.com/ubuntu focal/main amd64 liblua5.2-0 amd64 5.2.4-1.1build3 [106 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-bin amd64 2.4.41-4ubuntu3.8 [1,181 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-data all 2.4.41-4ubuntu3.8 [159 kB] 
Get:8 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2-utils amd64 2.4.41-4ubuntu3.8 [84.5 kB]
Get:9 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 apache2 amd64 2.4.41-4ubuntu3.8 [95.5 kB] 
Fetched 1,820 kB in 13s (135 kB/s) 
Selecting previously unselected package libapr1:amd64.
...
Processing triggers for ufw (0.36-6) ...
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...

2.2. Verifying Apache 2 Service

After installation was completed done, then we willv verify Apache 2 service. By default, Apache 2 service will be running after installation was completed. To verify it, we will query Apache 2 service, by submit the following command line :

$ sudo systemctl status apache2.service

Output :

ramansah@app01:~$ sudo systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-10-31 19:18:25 PDT; 3min 27s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 4564 (apache2)
Tasks: 55 (limit: 9443)
Memory: 4.8M
CGroup: /system.slice/apache2.service
├─4564 /usr/sbin/apache2 -k start
├─4565 /usr/sbin/apache2 -k start
└─4566 /usr/sbin/apache2 -k start

Oct 31 19:18:25 app01.otodiginet.com systemd[1]: Starting The Apache HTTP Server...
Oct 31 19:18:25 app01.otodiginet.com systemd[1]: Started The Apache HTTP Server.

3. Installing MariaDB

Drupal 9, requires Database to store its data. We will use MariaDB as our Drupal 9 backend databasea. If using Drupal 9 with MariaDB, version 10.3.7+ is required. MariaDB is a good open source database.

3.1. Install MariaDB

We will install it on our server, by typing the following command line.

$ sudo apt-get install mariadb-server mariadb-client -y

Output :

ramansah@app01:~$ sudo apt-get install mariadb-server mariadb-client -y
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
galera-3 gawk libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl
libfcgi-perl libhtml-template-perl libreadline5 libsigsegv2 libsnappy1v5 libterm-readkey-perl
mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server-10.3 mariadb-server-core-10.3 socat
Suggested packages:
gawk-doc libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl mailx
mariadb-test tinyca
The following NEW packages will be installed:
galera-3 gawk libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl
libfcgi-perl libhtml-template-perl libreadline5 libsigsegv2 libsnappy1v5 libterm-readkey-perl mariadb-client
mariadb-client-10.3 mariadb-client-core-10.3 mariadb-common mariadb-server mariadb-server-10.3
mariadb-server-core-10.3 socat
0 upgraded, 22 newly installed, 0 to remove and 353 not upgraded.
. . .
Setting up mariadb-client (1:10.3.31-0ubuntu0.20.04.1) ...
Setting up mariadb-server (1:10.3.31-0ubuntu0.20.04.1) ...
Processing triggers for systemd (245.4-4ubuntu3.11) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...

3.2. Managing MariaDB Service

By default, MariaDB sevice will be running after istallasion was completed. On this stage we will enable MariaDB service to startup after the server reboot. For this purpose, we will do the following commands :

$ sudo systemctl start mariadb.service
$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service
$ sudo systemctl status mariadb.service

Output :

ramansah@app01:~$ sudo systemctl stop mariadb.service
ramansah@app01:~$ sudo systemctl start mariadb.service
ramansah@app01:~$ sudo systemctl enable mariadb.service
ramansah@app01:~$ sudo systemctl status mariadb.service
● mariadb.service - MariaDB 10.3.31 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-10-31 19:29:42 PDT; 28s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 9431 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 9443)
Memory: 62.8M
CGroup: /system.slice/mariadb.service
└─9431 /usr/sbin/mysqld

Oct 31 19:29:42 app01.otodiginet.com systemd[1]: Starting MariaDB 10.3.31 database server...
Oct 31 19:29:42 app01.otodiginet.com mysqld[9431]: 2021-10-31 19:29:42 0 [Note] /usr/sbin/mysqld (mysqld 10.3.31->
Oct 31 19:29:42 app01.otodiginet.com systemd[1]: Started MariaDB 10.3.31 database server.
Oct 31 19:29:42 app01.otodiginet.com /etc/mysql/debian-start[9478]: Checking for insecure root accounts.
Oct 31 19:29:42 app01.otodiginet.com /etc/mysql/debian-start[9482]: Triggering myisam-recover for all MyISAM tabl>

3.3. Securing MariaDB

After installatin was completed, we will secure MariaDB from from the work of irresponsible people. To secure MariaDB we will do the following command line.

$ sudo mysql_secure_installation

Output :

ramansah@app01:~$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

3.4. Creating Drupal Database

On this stage, we will create a new database called as drupal on new MariaDB database engine which was installed. To create a database, we need to log in to MariaDB by using SQL script we will create a database and user for Drupal 9 CMS application.

$ sudo mysql -u root -p

The output :

ramansah@app01:~$ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 45
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE drupaldb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> GRANT ALL ON drupaldb.* TO 'drupal_user'@'localhost' IDENTIFIED BY 'drupal_passwd' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye

Now, we have had a database called as drupadb and a database user call as drupal_user.

4. Installing PHP 7.4

PHP is one of the important component of Drupal installation must be exist. Drupal 9 requires PHP 7.4 or higher to run properly. On this stage we will install PHP 7.4 on Ubuntu 20.04 system.

4.1. Install PHP 7.4

To install PHP 7.4 on Ubuntu 20.04, we will do the following task.

$ sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-gd php7.4-xml php7.4-intl php7.4-mysql php7.4-cli php7.4-zip php7.4-curl -y

Output :

ramansah@app01:~$ sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-gd php7.4-xml php7.4-intl php7.4-mysql php7.4-cli php7.4-zip php7.4-curl -y
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
libonig5 libxmlrpc-epi0 libzip4 php-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
php-pear
The following NEW packages will be installed:
libapache2-mod-php7.4 libonig5 libxmlrpc-epi0 libzip4 php-common php7.4 php7.4-cli php7.4-common php7.4-curl
php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-soap php7.4-xml
php7.4-xmlrpc php7.4-zip
0 upgraded, 20 newly installed, 0 to remove and 358 not upgraded.
. . .
Creating config file /etc/php/7.4/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.4
Setting up php7.4 (7.4.25-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
Processing triggers for php7.4-cli (7.4.25-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php7.4 (7.4.25-1+ubuntu20.04.1+deb.sury.org+1) ...

4.2. Verify PHP 7.4 Installation

To verifyt PHP version, we will query its version by submitting command line :

$ php --version

Output :

ramansah@app01:~$ php --version
PHP 7.4.25 (cli) (built: Oct 22 2021 12:34:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies

Now, we alreay have PHP version 7.4.25 installed on the system.

5. Installing and Configuring Drupal 9

Since all prerequisite software components are already installed on the system, we will install and configure Drupal 9 on the system.

5.1 . Download Drupal 9 Source File

On this stage, we will download Drupal 9 source fie by using wget command line.

$ wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz

Output :

ramansah@app01:~$ wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
--2021-10-31 20:50:01-- https://www.drupal.org/download-latest/tar.gz
Resolving www.drupal.org (www.drupal.org)... 199.232.46.217
Connecting to www.drupal.org (www.drupal.org)|199.232.46.217|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://ftp.drupal.org/files/projects/drupal-9.2.7.tar.gz [following]
--2021-10-31 20:50:02-- https://ftp.drupal.org/files/projects/drupal-9.2.7.tar.gz
Resolving ftp.drupal.org (ftp.drupal.org)... 199.232.46.217
Connecting to ftp.drupal.org (ftp.drupal.org)|199.232.46.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18863167 (18M) [application/octet-stream]
Saving to: ‘drupal.tar.gz’

drupal.tar.gz 100%[=================================================>] 17.99M 1.91MB/s in 9.0s

2021-10-31 20:50:11 (2.00 MB/s) - ‘drupal.tar.gz’ saved [18863167/18863167]

5.2. Extract Drupal 9 Source

$ tar xvf drupal.tar.gz
$ sudo mv drupal-*/ /var/www/html/drupal
$ cd /var/www/html
$ sudo chown -R www-data:www-data /var/www/html/
$ sudo chmod -R 755 /var/www/html/

Output :

ramansah@app01:~$ tar xvf drupal.tar.gz
ramansah@app01:~$ sudo mv drupal-*/ /var/www/html/drupal
ramansah@app01:/home$ cd /var/www/html
ramansah@app01:/var/www/html$ ls -ltr
total 20
drwxr-xr-x 8 ramansah ramansah 4096 Oct 6 11:18 drupal
-rw-r--r-- 1 root root 10918 Oct 31 19:18 index.html
-rw-r--r-- 1 root root 22 Oct 31 20:40 phpinfo.php
ramansah@app01:/var/www/html$ sudo chown -R www-data:www-data /var/www/html/
[sudo] password for ramansah: 
ramansah@app01:/var/www/html$ ls -ltr
total 20
drwxr-xr-x 8 www-data www-data 4096 Oct 6 11:18 drupal
-rw-r--r-- 1 www-data www-data 10918 Oct 31 19:18 index.html
-rw-r--r-- 1 www-data www-data 22 Oct 31 20:40 phpinfo.php

5.3. Configuring Apache For Drupal

On this stage, we will configure Apache for Drupal. The configuration file is located on /etc/apache2/sites-available/drupal.conf. We will modify this file as following.

ramansah@app01:/var/www/html$ sudo vi /etc/apache2/sites-available/drupal.conf

<VirtualHost *:80>
ServerName app01.otodiginet.com
ServerAlias app01.otodiginet.com
ServerAdmin admin@otodiginet.com
DocumentRoot /var/www/html/drupal/

CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log

<Directory /var/www/html/drupal>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
ramansah@app01:/var/www/html$ sudo apachectl -t
Syntax OK
ramansah@app01:/var/www/html$ sudo a2dismod mpm_event
Module mpm_event already disabled
ramansah@app01:/var/www/html$ sudo a2enmod mpm_prefork
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
ramansah@app01:/var/www/html$ sudo sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.4:
Module php7.4 already enabled
ramansah@app01:/var/www/html$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
systemctl restart apache2
ramansah@app01:/var/www/html$ sudo a2ensite drupal.conf
Enabling site drupal.
To activate the new configuration, you need to run:
systemctl reload apache2

5.4. Drupal 9 Instalation

After all are set, Drupal 9 installation will be handled via web browser. On this tutorial we will use a domain name rather than ip address. For the installation we will use URL where the domain name have been set up on the apache2 configuration file.

Install Drupal 9 on Ubuntu 20.04

Follow all instruction on this installation guide and we will finish all steps.

Welcome to Drupal 9

Conlusion

On this short tutorial we have tried to install Drupal 9 CMS on Ubuntu 20.04 LTS operating system. I hope this article could be helpful.

Add a Comment

Your email address will not be published.