How to install Drupal 9 CMS on Ubuntu 20.04

You can support us by downloading this article in PDF format through the following link.

Download the guide in PDF format

turn off


Drupal 9 is the latest version of the popular Drupal content management system (CMS). Drupal is a community-driven platform for building amazing digital experiences. It enables content creators to add, edit, publish or delete content on the 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 released under the GNU General Public License. Drupal 9 represents the culmination of all the features developed by Drupal 8 on a leaner and cleaner code base. Some features in Drupal 9 include:

  • Layout generator: Allow content editors to design pages without engineering assistance
  • API First Architecture: Support for building robust decoupling and headless applications
  • Media Library: Makes the management of images, videos and other assets easier than ever.
  • Automatic update
  • New management interface and default theme

Drupal 9 system requirements

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

Now, we can introduce the steps to install Drupal 9 CMS on Ubuntu 20.04 Linux system.

Step 1: Update the system

Make sure your system has been updated to the latest version:

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

Wait for the server to start, then ssh and continue with the configuration.

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

Step 2: Install MariaDB database server

We will use MariaDB as our database server. The software package of the database server is available in the OS upstream repository. Trigger the following command to install.

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

Protect the security of the database server by setting the root password, disabling root remote login, and deleting the test database we do not need.

$ sudo mysql_secure_installation


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 ordinary users to log in as the root user with a password.

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

Test if you can log in to the database as the root user with a password

$ 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 a Drupal database

Drupal CMS requires a database and users to function properly. Open the MariaDB shell.

$ mysql -u root -p

Create databases and users for Drupal.

GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '[email protected]';

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}

Make sure that Apache is installed.

sudo apt install apache2 libapache2-mod-php

Set PHP time zone 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 that will run the service.

wget -O drupal.tar.gz

Unzip the downloaded file.

tar xvf drupal.tar.gz

Move the result folder to the /var/www/html directory.

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

Confirm the content of the file:

$ 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 the ownership of the drupal directory to Apache users and groups.

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 the Drupal website.

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

Modify the following and add it to the file-setting domain, administrator user and correct Drupal data path.

     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 the configuration syntax:

sudo apachectl -t

Enable the 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

To start Drupal’s network configuration, you need to configure a valid DNS entry in Apache.

Choose a language:

Choose an installation configuration file:

How to install Drupal 9 CMS on Ubuntu 20.04

Configure the database for Drupal:

How to install Drupal 9 CMS on Ubuntu 20.04

Drupal installation begins. Wait for it to complete:

How to install Drupal 9 CMS on Ubuntu 20.04

Configure your site:

How to install Drupal 9 CMS on Ubuntu 20.04

Enjoy the power of Drupal 9 in your website. See Official documents Make more adjustments and advanced configuration.

You can support us by downloading this article in PDF format through the following link.

Download the guide in PDF format

turn off