How to install Drupal CMS on Ubuntu 22.04

To Install Drupal CMS On Ubuntu 22.04

Introduction

Drupal is a flexible CMS based on the LAMP stack, with a modular design allowing features to be added and removed by installing and uninstalling modules and allowing the entire look and feel of the website to be changed by installing and uninstalling themes.

procedure Steps:

Step 1: Check the OS version by using the below command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:    22.04
Codename:    jammy

Step 2: Now install MariaDB client and server by using the below command

root@linuxhelp:~# apt install -y mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libflashrom1 libftdi1-2 libllvm13
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl libmariadb3
  libmysqlclient21 libndctl6 libpmem1 libsigsegv2 libsnappy1v5 libterm-readkey-perl liburing2 mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server-10.6 mariadb-server-core-10.6
  mysql-common socat
Suggested packages:
  gawk-doc libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl mailx mariadb-test
The following NEW packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-template-perl libmariadb3
  libmysqlclient21 libndctl6 libpmem1 libsigsegv2 libsnappy1v5 libterm-readkey-perl liburing2 mariadb-client mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server
Setting up mariadb-server (1:10.6.12-0ubuntu0.22.04.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

Step 3: Now check the status of the MariaDB service by using the below command

root@linuxhelp:~# systemctl status mariadb
● mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-10-16 17:14:36 IST; 1min 45s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 6552 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 6554 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 6556 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITIO>
    Process: 6602 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 6604 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 6585 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 10 (limit: 4556)
     Memory: 61.5M
        CPU: 824ms
     CGroup: /system.slice/mariadb.service
             └─6585 /usr/sbin/mariadbd

Step 4: Login to the MariaDB console by using the below command

root@linuxhelp:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.6.12-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.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.

Step 5: Create a database by using the below command

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

Step 6: Create a user by using the below command

MariaDB [(none)]> CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.001 sec)

Step 7: Now Grant All privileges for the user to access that database by using the below command

MariaDB [(none)]> GRANT ALL PRIVILEGES ON drupal.* to drupal_user@'localhost';
Query OK, 0 rows affected (0.001 sec)

Step 8: Flush the privileges by using the below command

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

Step 9: Now Exit from the MariaDB console by using the below command

MariaDB [(none)]> \q
Bye

Step 10: Install PHP with it dependency modules by using the below command

root@linuxhelp:~# apt install php php-{cli,fpm,json,common,mysql,zip,gd,intl,mbstring,curl,xml,pear,tidy,soap,bcmath,xmlrpc}
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libflashrom1 libftdi1-2 libllvm13
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libonig5 libtidy5deb1 libxmlrpc-epi0 libzip4 php8.1 php8.1-bcmath
  php8.1-cli php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-soap php8.1-tidy php8.1-xml php8.1-xmlrpc php8.1-zip
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libonig5 libtidy5deb1 libxmlrpc-epi0 libzip4 php php-bcmath php-cli
  php-common php-curl php-fpm php-gd php-intl php-json php-mbstring php-mysql php-pear php-soap php-tidy php-xml php-xmlrpc php-zip php8.1 php8.1-bcmath php8.1-cli php8.1-common php8.1-curl php8.1-fpm
  php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-soap php8.1-tidy php8.1-xml php8.1-xmlrpc php8.1-zip
0 upgraded, 47 newly installed, 0 to remove and 86 not upgraded.
Need to get 10.9 MB of archives.
After this operation, 42.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libapr1 amd64 1.7.0-8ubuntu0.22.04.1 [108 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1 amd64 1.6.1-5ubuntu4.22.04.2 [92.8 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libaprutil1-dbd-sqlite3 

Step 11: Now going to increase memory size in the php.ini file by using the below command

root@linuxhelp:~# vim /etc/php/*/apache2/php.ini
memory_limit = 256M
Step 12: Download the Drupal package by using the wget command
root@linuxhelp:~# wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
--2023-10-16 17:26:57--  https://www.drupal.org/download-latest/tar.gz
Resolving www.drupal.org (www.drupal.org)... 199.232.254.217
Connecting to www.drupal.org (www.drupal.org)|199.232.254.217|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://ftp.drupal.org/files/projects/drupal-10.1.5.tar.gz [following]
--2023-10-16 17:26:58--  https://ftp.drupal.org/files/projects/drupal-10.1.5.tar.gz
Resolving ftp.drupal.org (ftp.drupal.org)... 199.232.254.217
Connecting to ftp.drupal.org (ftp.drupal.org)|199.232.254.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18285113 (17M) [application/octet-stream]
Saving to: ‘drupal.tar.gz’

drupal.tar.gz                                      100%[==============================================================================================================>]  17.44M  10.4MB/s    in 1.7s

2023-10-16 17:26:59 (10.4 MB/s) - ‘drupal.tar.gz’ saved [18285113/18285113]

Step 12: Extract the downloaded package by using the tar command

root@linuxhelp:~# tar xvf drupal.tar.gz
drupal-10.1.5/
drupal-10.1.5/vendor/
drupal-10.1.5/vendor/composer/
drupal-10.1.5/vendor/composer/semver/
drupal-10.1.5/vendor/composer/semver/CHANGELOG.md
drupal-10.1.5/vendor/composer/semver/LICENSE
drupal-10.1.5/vendor/composer/semver/README.md
drupal-10.1.5/vendor/composer/semver/composer.json
drupal-10.1.5/vendor/composer/semver/src/
drupal-10.1.5/vendor/composer/semver/src/Comparator.php
drupal-10.1.5/autoload.php
drupal-10.1.5/composer.json
drupal-10.1.5/composer.lock
drupal-10.1.5/LICENSE.txt

Step 13: Move the Extracted folder to the Apache document root directory by using the below command

root@linuxhelp:~# mv drupal-*/  /var/www/html/drupal

Step 14: Change the ownership of the folder by using the below command

root@linuxhelp:~#  chown -R web-data: /var/www/html/

Stap 15: Change the permission of the folder using following command

root@linuxhelp:~#  chmod -R 755 /var/www/html/

Step 16: Now create a virtual host file by using the below command

root@linuxhelp:~# vim /etc/apache2/sites-available/drupal.conf
<VirtualHost *:80>
     ServerName linuxhelp.xyz
     ServerAdmin admin@linuxhelp.xyz
     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>

Step 17: Now check the syntax of the Apache by using the below command

root@linuxhelp:~#  apachectl -t
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Step 18: Enable rewrite module by using the below command

root@linuxhelp:~#  a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2

Step 19: Enable site configuration by using the below command

root@linuxhelp:~#  a2ensite drupal.conf
Enabling site drupal.
To activate the new configuration, you need to run:
  systemctl reload apache2

Step 20: Restart the Apache service by using the below command

root@linuxhelp:~# systemctl restart apache2

Now go to the browser and search with your IP or domain as shown in the below image

Then select the Installation method and enter the database credential as shown in the below image

Now enter the Site Details as shown in the below image

Now you will seen the welcome page of you site as shown in the below image

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to installation of Drupal CMS on Ubuntu 22.04. Your feedback is much welcome.

FAQ
Q
How to reload the privileages in MariaDB?
A
Use the following query to flush the privileges on MariaDB
# FLUSH PRIVILEGES;
Q
How to create a database in MariaDB?
A
You can create a database in MariaDB by using the following query
# CREATE DATABASE ‘database_name’;
Q
How to create a user in MariaDB?
A
You can create a user in MariaDB by using the following query
# CREATE USER ‘usename’@’localhost’ IDENTIFIED BY ‘your_password’;
Q
How to install mariadb-server on Ubuntu?
A
Use the following command to install Apache2 on Ubuntu
# apt install mariadb-server
Q
How to install Apache2 on Ubuntu?
A
Use the following command to install Apache2 on Ubuntu
# apt install apache2