December 3, 2021
How to install Drupal 9 on Ubuntu 20.04

How To Install Drupal 9 On Ubuntu 20.04 LTS

On this tutorial we will learn how to install Drupal 9.2.7 on Ubuntu 20.04 LTS operating system.

Introduction

Drupal is open-source and free web content management system (CMS) written in PHP and distributed under the GNU General Public License. Drupal runs on the server side, allows the creation of dynamic websites, provides a back-end framework for at least 13% of the top 10,000 websites worldwide. Drupal will be an another options beside popular CMS tools such as WordPress or Joomla. Drupal 9 is the most recent version of Drupal which was released on Drupal 9 was released on June 3, 2020. On this tutorial we will learn how to install Drupal 9 on Ubuntu 20.04 LTS operating system.

Drupal 9 Installation On Ubuntu 20.04 Linux Operating System

Drupal 9 is the most recent version of Drupal CMS application system, where Drupal 8’s end of life is coming 2 November 2021. The key benefit of Drupal 9 over Drupal 8 is the platform will be supported with security fixes after November 2021. The standout feature of Drupal 9 is its ability to provide as easy an upgrade as feasible from Drupal 8.

Drupal 9 System Requirements

  1. Database server requirements
    Drupal supports for many relational database management system. Drupal 9 requires MariaDB 10.3+ or MySQL/Percona 5.7.8+, PostgreSQL 10.0 or higher, SQLite 3.26 or higher,
  2. 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.
  3. PHP requirements
    PHP version 7.4 or higher for current release versions of Drupal 9.

Drupal 9 Installation Steps

On this section, we will cover the steps for installing Drupal 9 CMS on Ubuntu 20.04 Linux system. Based on system requirements above, we will use MariaDB version 10.3, Apache version 2.4.7 and PHP version 7.4.

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

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:

$ sudo apt update

Install Apache2

On this tutorial, we will use Apache 2 as web server. Apache is one of the most popular web servers nowadays. To install it we will refer to official Ubuntu repositories. We will use command line :

$ sudo apt install apache2 -y
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.

By default, Apache 2 service will be running after installation was completed done. We will restart and enable Apache 2 Service by typing command line :

$ sudo systemctl stop apache2.service
$ sudo systemctl start apache2.service
$ sudo systemctl enable apache2.service
$ sudo systemctl status apache2.service
ramansah@app01:~$ sudo systemctl stop apache2.service
ramansah@app01:~$ sudo systemctl start apache2.service
ramansah@app01:~$ sudo systemctl enable apache2.service
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
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:22:10 PDT; 12s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 6532 (apache2)
      Tasks: 55 (limit: 9443)
     Memory: 4.8M
     CGroup: /system.slice/apache2.service
             ├─6532 /usr/sbin/apache2 -k start
             ├─6533 /usr/sbin/apache2 -k start
             └─6534 /usr/sbin/apache2 -k start

Oct 31 19:22:10 app01.otodiginet.com systemd[1]: Starting The Apache HTTP Server...
Oct 31 19:22:10 app01.otodiginet.com systemd[1]: Started The Apache HTTP Server.
Install Drupal 9 | Restarting Apache 2 Service
Install Drupal 9 | Restarting Apache2 Service
Install Drupal 9 | Apache2 Web interface
Install Drupal 9 | Apache 2 Web interface

Installing MariaDB

We will use MariaDB as our Drupal 9 backend databasea. MariaDB is a good open source database. We will install it on our server, by typing the following command:

$ sudo apt-get install mariadb-server mariadb-client -y
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.
Need to get 20.2 MB of archives.
After this operation, 167 MB of additional disk space will be used.

We will make MariaDB database to be run at Server startup, as it is a component that works in parallel with Drupal. To make this operation we will restart and enable MariaDB service by typing command line :

$ sudo systemctl stop mariadb.service
$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service
$ sudo systemctl status mariadb.service
Drupal 9 Installation | Restart MariaDB Services
Drupal 9 Installation | Restart MariaDB Services

We will ensecure our MariaDB Database to increase security on our backed database. We will type the following command line :

$ sudo mysql_secure_installation

We will be requested to specify a range of information. Follow the list below for the configuration.

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.

To verify that MariaDB has been installed correctly, we will log in to the database and query its version by typing command line:

Thanks for using MariaDB!amansah@app01:~$ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44
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)]> select version();
+----------------------------------+
| version()                        |
+----------------------------------+
| 10.3.31-MariaDB-0ubuntu0.20.04.1 |
+----------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> quit;
Bye
Drupal 9 Installation | MariaDB version 10.3.31
Drupal 9 Installation | MariaDB version 10.3.31

Installing PHP 7.4

Drupal 9 requires PHP 7.3 or higher to live in. On this tutorial, we will install PHP version 7.4. PHP is not available in the official Ubuntu repositories, therefore it has to be installed using third-party repositories.

Add Support Repository And Update Package

$ sudo apt-get install software-properties-common -y
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update

Install PHP 7.4

After all supporting package was installed, then we will install PHP 7.4 by typing command line :

$ 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
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.
Need to get 5,299 kB of archives.
After this operation, 22.2 MB of additional disk space will be used.
...
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) ...

Then we will update /etc/php/7.4/apache2/php.ini file for parameters below :

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360

Then we will verify PHP 7.4 version by querying its version.

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
Drupal 9 | install PHP 7.4
Drupal 9 | install PHP 7.4

We also will verify that the installation of PHP 7.4 has been successful by restarting Apache and creating a phpinfo.php file in the Apache root.

ramansah@app01:~$ sudo vi /var/www/html/phpinfo.php
[sudo] password for ramansah: 
?php phpinfo(); ?>
PHP version 7.4.25
PHP version 7.4.25

Setting Up Drupal 9 Database

In this section, we will create a database that will be used for Drupal 9. We will create a new database called as : drupaldb and a new user called as dupal_user.

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
Drupal 9 Database Creationg on MariaDB
Drupal 9 Database Creationg on MariaDB

Installing And Configuring Drupal 9

Until now, the preparations for Drupal 9 CMS installation have been completed. Then we ill download the software and configure it. We will download the latest Drupal 9, with the following commands :

$ wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
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] 
Drupal 9 Download
Drupal 9 Download

After Drupal 9 download has been completed done, then we will extract and move it to the /var/www/html/ directory.

ramansah@app01:~$ ls -ltr *.gz
total 18460
-rw-rw-r-- 1 ramansah ramansah 18863167 Oct  6 11:19 drupal.tar.gz
ramansah@app01:~$ tar xvf drupal.tar.gz
ramansah@app01:~$ sudo mv drupal-*/  /var/www/html/drupal
ramansah@app01:~$ ls -ltr /var/www/html/drupal
total 248
-rw-r--r--  1 ramansah ramansah  18092 Nov 16  2016 LICENSE.txt
-rw-r--r--  1 ramansah ramansah   4016 Oct  6 11:18 web.config
drwxr-xr-x 19 ramansah ramansah   4096 Oct  6 11:18 vendor
-rw-r--r--  1 ramansah ramansah    804 Oct  6 11:18 update.php
drwxr-xr-x  2 ramansah ramansah   4096 Oct  6 11:18 themes
drwxr-xr-x  3 ramansah ramansah   4096 Oct  6 11:18 sites
-rw-r--r--  1 ramansah ramansah   1586 Oct  6 11:18 robots.txt
-rw-r--r--  1 ramansah ramansah   3205 Oct  6 11:18 README.md
drwxr-xr-x  2 ramansah ramansah   4096 Oct  6 11:18 profiles
drwxr-xr-x  2 ramansah ramansah   4096 Oct  6 11:18 modules
-rw-r--r--  1 ramansah ramansah     94 Oct  6 11:18 INSTALL.txt
-rw-r--r--  1 ramansah ramansah    549 Oct  6 11:18 index.php
-rw-r--r--  1 ramansah ramansah   1507 Oct  6 11:18 example.gitignore
drwxr-xr-x 12 ramansah ramansah   4096 Oct  6 11:18 core
-rw-r--r--  1 ramansah ramansah 171393 Oct  6 11:18 composer.lock
-rw-r--r--  1 ramansah ramansah   3156 Oct  6 11:18 composer.json
-rw-r--r--  1 ramansah ramansah    312 Oct  6 11:18 autoload.php
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
ramansah@app01:/var/www/html$ sudo chmod -R 755 /var/www/html/

Configuring Drupal and Apache2

At this point, we will configure Apache2 for Drupal. We will configure a Virtual Host to allow website to be published. Create a configuration file to specify which users can access the service. The file is called as /etc/apache2/sites-available/drupal.conf. For this tutorial, the file’s contens is as shown below :

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>

We will enable this new configuration file in order for Apache2 to take it into account at the next restart.

$ sudo apachectl -t
$ sudo a2dismod mpm_event
$ sudo a2enmod mpm_prefork
$ sudo sudo a2enmod php7.4
$ sudo a2enmod rewrite
$ sudo a2ensite drupal.conf
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
Drupal 9 Configuration File
Drupal 9 Configuration File

Drupal 9 Configuration

On this section, we will configure Drupal by accessing the Drupal configuration page by accessing URL:

http://localhost/drupal on our tutorial we will use http://app01.otodiginet.com/drupal
Drupal 9 Installation | Choose Language
Drupal 9 Installation | Choose Language
Drupal 9 Installation | Select an Installation profile
Drupal 9 Installation | Select an Installation profile
Drupal 9 Installation | Verify requirements
Drupal 9 Installation | Verify requirements
Drupal 9 Installation | Database Configuration
Drupal 9 Installation | Database Configuration

In the last section, we will specify the information for our site, the email address and the login data for the administrator. When this last phase is completed, the Drupal backend homepage, announcing that the installation was successful.

Drupal 9 Installation | First page

Now, the Drupal 9 installation is completed done. From this section we could to manage our Drupal framework according to our needs.

Conclusion

In this article we have shown you how to install Drupal 9 CMS on Ubuntu 20.04 LTS operating system successfully. I hope that this article is useful for those of you who need it. Detail information about Drupal 9 can be found on Drupal official website.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *