Drupal is a free open source system and one of the most popular CMS platforms in the world. It is written in PHP and uses MariaDB as its database backend. It is used for creating various types of websites and blogs. It is a simple, modular and highly customizable CMS and an alternative CMS solution for other popular CMSs like WordPress or Drupal. Drupal has a user-friendly web interface that allows website creators to add, edit, publish or remove content through the web browser.

In this post, we will show you how to install Drupal CMS with Apache and Let’s Encrypt SSL on Ubuntu 22.04.

Requirements

  • A server running Ubuntu 22.04.
  • A valid domain name pointing to your server’s IP.
  • A root password configured on the server.

Install LAMP server

First you need to install Apache web server, MariaDB database server, PHP and other required PHP extensions on your server. You can install them all with the following command:

apt-get install apache2 mariadb-server php libapache2-mod-php php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-intl php-mbstring php-curl php-xml php-pear php-tidy php-soap php-bcmath php-xmlrpc -y

Once all packages are installed, edit the PHP configuration file and change some default values:

nano /etc/php/8.1/apache2/php.ini

Change the following lines:

memory_limit = 256M
date.timezone = UTC

Save and close the file and restart the Apache service to apply the changes:

systemctl restart apache2

Create a database for Drupal

Next, you need to create a database and a user for Drupal. First, log in to MariaDB with the following command:

mysql

Once logged in, create a database and user with the following command:

CREATE DATABASE drupal;
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'password';

Next, grant the Drupal database all permissions with the following command:

GRANT ALL PRIVILEGES ON drupal.* to drupaluser@'localhost';

Clear the permissions and exit the MariaDB shell with the following command:

FLUSH PRIVILEGES;
EXIT;

Download Drupal CMS

Go to the Drupal download page and download the latest version of Drupal with the following command:

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

Once the download is complete, extract the downloaded file using the following command:

tar xvf drupal.tar.gz

Move the extracted directory to the Apache web root using the following command:

mv drupal-9.3.13 /var/www/html/drupal

Next, change the ownership and access rights for the Drupal directory:

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

When you are done with this, you can proceed to the next step.

Configure Apache for Drupal

Next, create a configuration file for the Apache virtual host for Drupal using the following command:

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

Add the following configuration:

     ServerName drupal.example.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]
   

Save and close the file and enable the required Apache modules with the following command:

a2dismod mpm_event
a2enmod mpm_prefork
a2enmod rewrite

Next, activate the configuration file for the Drupal virtual host with the following command.

a2ensite drupal.conf

Then restart the Apache service to apply the changes.

systemctl restart apache2

Then check the status of the Apache service with the following command:

systemctl status apache2

You should see the following output:

? apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-05-12 16:36:29 UTC; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 27121 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 27125 (apache2)
      Tasks: 6 (limit: 2292)
     Memory: 14.4M
        CPU: 96ms
     CGroup: /system.slice/apache2.service
             ??27125 /usr/sbin/apache2 -k start
             ??27126 /usr/sbin/apache2 -k start
             ??27127 /usr/sbin/apache2 -k start
             ??27128 /usr/sbin/apache2 -k start
             ??27129 /usr/sbin/apache2 -k start
             ??27130 /usr/sbin/apache2 -k start

May 12 16:36:29 ubuntu systemd[1]: Starting The Apache HTTP Server...

Accessing the Drupal web interface.

Now open your web browser and access the Drupal web interface using the URL http://drupal.example.com. You should see the language selection screen:

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

Select your language and click the Save and Continue button. You should see the installation profile selection screen:

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

Select your installation option and click the Save and Continue button. You should see the database configuration screen:

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

Enter your database information and click the Save and Continue button. You should see the site configuration screen:

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

Enter your site information and click the Save and Continue button. Once Drupal is installed, you should see the Drupal dashboard on the following screen:

How to Install Drupal CMS with Let’s Encrypt SSL on Ubuntu 22.04 linux ubuntu

Securing Drupal with Let’s Encrypt SSL.

It’s always a good idea to secure your website with Let’s Encrypt SSL. To install and manage the SSL, you need to install the Certbot client. You can install it with the following command:

apt-get install python3-certbot-apache -y

Once Certbot is installed, run the following command to secure your website with Let’s Encrypt SSL:

certbot --apache -d drupal.example.com

You will be asked to provide your email address and accept the terms of service (see below):

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for drupal.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/drupal-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/drupal-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/Drupal-le-ssl.conf

Next, select whether or not to redirect HTTP traffic to HTTPS (see below):

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Type 2 and press Enter to install Let’s Encrypt SSL for your website:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/Drupal.conf to ssl vhost in /etc/apache2/sites-available/drupal-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://drupal.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=drupal.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/drupal.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/drupal.example.com/privkey.pem
   Your cert will expire on 2022-08-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Now you can safely access your website via the URL https://drupal.example.com .

Conclusion

Congratulations! You have successfully installed Drupal with Apache and Let’s Encrypt SSL on Ubuntu 22.04. You can now create your own website or blog with the Drupal CMS.