How to install Drupal 9.3 on Ubuntu 20.04

Drupal 9.3 is one of the best CMS out there. In this tutorial, I am going to show you how to install Drupal 9 on your Ubuntu 20.04|22.04. Let’s get started.

Drupal is a free and open-source web content management system powered by PHP. It is a highly flexible platform for digital innovation. The reason why Drupal is so important is because of its availability and is free and open-source. No license is needed to operate it. It has a larger community meaning any time you experience an issue with the platform you can always turn to a ready-to-help community.

Features of Drupal 9.3

  • It provides easy content authoring for all the content creators.
  • It provides easy and reliable performance, you will hardly get issues whwnever you are using Drupal CMS.
  • Content Management system needs to be impenetrable therefore security is key thats why drupal 9 is the epitome of sucurity success.
  • It provides flexibility. Its tools helps you build the versatile, structured content needed for dynamic websites.
  • Extending modules in drupal is easy thanks to digital integrated frameworks.
  • Its powerful and can scale much faster.

What you need to run Drupal 9.3

These are system requirements needed to operate Drupal CMS.

  • Have a database such as MySQL 5.7 or higher or Postresql 10 or higher
  • Drupal works well on Apache, Nginx
  • It needs PHP 7.3 and higher

Installling Drupal 9.3 on Ubuntu 20.04|22.04

The first thing before we can install Drupal on our system is to run system updates so that we can avoid running into errors at a later stage in our installation.

sudo apt update && apt upgrade -y

1. Install MariaDB database

The second thing to do after updating our system is to install MariaDB or PostgreSQL. I will be using MariaDB for this process. So let’s install MariaDB with the following command.

sudo apt install mariadb-server mariadb-client -y

For any database, we are required to secure it before we can use it. So to secure our installed MariaDB database run the following command.

sudo mysql_secure_installation

# output
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] n 
 ... skipping.

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!

When this is complete, then we need to allow regular users to log in as root with the following command.

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

Now that we are able to log in as regular users, we can now create a Drupal database that Drupal can use once we installed it into our system. To create one use the following command:

# login command
mysql -u root -p

Once logged in create the database with the following command:

MariaDB [(none)]> Create database nextdrupal;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> Grant all privileges on nextdrupal.* to 'nextdrupal'@'localhost' identified by 'passwd';
Query OK, 0 rows affected (0.000 sec)

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

MariaDB [(none)]> quit
Bye

2. Install PHP

Now we can install PHP 7.3 or higher. If you love installing PHP using PPA repositories follow this link to read more about How to install PHP 8.1 on Ubuntu 20.04. Otherwise use the below command to continue the installation.

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

The following command will install all PHP and its dependencies at a go.

3. Install Apache web server

Install apache web server with the following command. Note that apache is recommended over Nginx. Read more here on how to install Apache 2 on Ubuntu 20.04.

sudo apt install apache2

Make sure the time zone is reading the place you are. For my case, I am setting the time zone to be Africa/Nairobi. You can do so like this sudo nano /etc/php/*/apache2/php.ini. I will be using nano as my preferred text editor

sudo nano /etc/php/*/apache2/php.ini

Set out memory limit and time zone.

4. Install Drupal 9.3 on Ubuntu 20.04|22.04

Now that all the prerequisites have been met, it’s now time we download and install Drupal. We are going to use the wget command to do so.

wget https://ftp.drupal.org/files/projects/drupal-9.3.7.tar.gz

When the download is complete, we need to extract the archive.

sudo tar -xvf drupal.tar.gz

Then we need to move it to var/www/html directory using the following command.

rm -f drupal*.tar.gz
sudo mv drupal drupal-9.3.7/ drupal

After this, we need to set Apache2 ownership by giving permission to the drupal files.

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

4. Create Apache 2 virtual host file.

We can create Apache virtual host file for Drupal with the following command.

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

This creates drupal.conf file. Add the following:

<VirtualHost *:80>
  Server Admin [email protected]
 DocumentRoot /var/www/html/drupal/ 
Server Name example.com ServerAlias www.example.com 
ErrorLog ${APACHE_LOG_DIR}/error.log 
CustomLog ${APACHE_LOG_DIR}/access. log combined 
Options FollowSymlinks 
AllowOverride All 
Require all granted 
RewriteEngine on 
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA)
</VirtualHost>

Save and restart the apache 2

sudo systemctl restart apache2

Enable Drupal site with the following:

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

Lastly restart apache again.

5. Configure Drupal 9.3 via Wizzard.

Now we can start our Drupal by going into our favorite browser and opening http://<your-ip-address/drupal>

Installing wizard will appear like this:

install Drupal 9.3
install Drupal 9.3

Conclusion

We have successfully installed drupal 9.3 on our Ubuntu 20.04. Play along with the CMS to learn more. For more info check out Drupal documentation.

About Mason Kipward

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Mason Kipward →

Leave a Reply

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