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.

Install Drupal 9 CMS on Ubuntu 20.04 Linux

The Drupal software is written in PHP and distributed under the GNU General Public License. Drupal 9 represents the culmination of all of the features developed over the course of Drupal 8, on a leaner, cleaner codebase. Some of the features in Drupal 9 are:

  • Layout Builder: Allows content editors to design pages without engineering help
  • API-first architecture: Enables building robust decoupled and headless applications
  • Media Library: Makes the management of images, video, and other assets easier than ever before.
  • Automated updates
  • New admin interface and default theme

Drupal 9 system requirements

  • PHP >=7.3
  • MySQL or Percona, version >=5.7.8
  • MariaDB >=10.3.7
  • PostgreSQL >=10

We can now cover the steps for installing Drupal 9 CMS on Ubuntu 20.04 Linux system.

Step 1: Update System

Ensure your system is updated to the latest release:

sudo apt update
sudo apt -y upgrade && sudo systemctl reboot

Wait for the server to come up then ssh and continue with the configuration.

$ ssh [email protected] || ssh [email protected]

Step 2: Install MariaDB database server

We’ll use MariaDB as our database server. The packages for this database server are available on the OS upstream repositories. Fire the following commands to get it installed.

sudo apt update
sudo apt install -y mariadb-server mariadb-client

Secure your database server by setting root password, disabling root remote logins and removing test databases that we don’t need.

$ 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!

Allow normal users to login as root user with a password.

$ sudo mysql -u root
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root';
FLUSH PRIVILEGES;
QUIT;

Test that you can login to database as root user with password set

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 59
Server version: 10.3.22-MariaDB-1ubuntu1 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)]>

Step 3: Create Drupal Database

A database and user is required by Drupal CMS to be functional. Open MariaDB shell.

$ mysql -u root -p

Create database and user for Drupal.

CREATE DATABASE drupal;
GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '[email protected]';
FLUSH PRIVILEGES;
q

Step 4: Install PHP and Apache Web Server

Install PHP on Ubuntu:

sudo apt install php php-{cli,fpm,json,common,mysql,zip,gd,intl,mbstring,curl,xml,pear,tidy,soap,bcmath,xmlrpc}

Ensure Apache is installed.

sudo apt install apache2 libapache2-mod-php

Set PHP Timezone and memory limit.

$ sudo vim /etc/php/7.4/apache2/php.ini
memory_limit = 256M
date.timezone = Africa/Nairobi

Step 5: Download Drupal 9 on Ubuntu 20.04

Download the Drupal 9 tarball to the host where the service will run.

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

Extract downloaded file.

tar xvf drupal.tar.gz

Move resulting folder to /var/www/html directory.

rm -f drupal*.tar.gz
sudo mv drupal-*/  /var/www/html/drupal

Confirm file contents:

$ ls /var/www/html/drupal
autoload.php   core               INSTALL.txt  profiles    sites       vendor
composer.json  example.gitignore  LICENSE.txt  README.txt  themes      web.config
composer.lock  index.php          modules      robots.txt  update.php

Set ownership of drupal directory to Apache user and group.

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

Step 6: Configure Apache for Drupal

Create a new Apache configuration for Drupal website.

sudo vim /etc/apache2/sites-available/drupal.conf

Modify below content and add to file – set domain, admin user and correct path to Drupal data.


     ServerName mysite.com
     ServerAlias www.mysite.com
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/drupal/

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

      
            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]
   

Confirm configuration syntax:

sudo apachectl -t

Enable website.

sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo sudo a2enmod php7.4
sudo a2enmod rewrite
sudo a2ensite drupal.conf
systemctl restart apache2

Step 7: Install Drupal 9 on Ubuntu 20.04

For the Drupal’s web configuration to be initiated, a valid DNS entry configured in Apache is required.

Choose Language:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/06/echo/Install-Drupal-Ubuntu-01-1024×575.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Select an installation profile:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/06/echo/Install-Drupal-Ubuntu-02-1024×521.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Configure Database for Drupal:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/06/echo/Install-Drupal-Ubuntu-03-1024×575.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Drupal installation is started. Wait for it to complete:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/06/echo/Install-Drupal-Ubuntu-04-1024×575.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Configure your site:

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/06/echo/Install-Drupal-Ubuntu-06-1024×580.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Enjoy the power of Drupal 9 in your website. Refer to the official documentation for more tuning and advanced configurations.