RHEL BasedRocky Linux

How To Install Drupal on Rocky Linux 9

Install Drupal on Rocky Linux 9

In this tutorial, we will show you how to install Drupal on Rocky Linux 9. For those of you who didn’t know, Drupal is a powerful content management system that can help you grow revenue and establish long-term loyalty with your customers by having a fast and reliable website. Drupal provides a robust content management tool with sophisticated APIs for multichannel publishing.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Drupal Content Management System on Rocky Linux. 9.

Prerequisites

  • A server running one of the following operating systems: Rocky Linux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Drupal.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Drupal on Rocky Linux 9

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update
sudo dnf install dnf-utils

Step 2. Installing Apache.

By default, Apache is available on the Rocky Linux 9 base repository. Now we install the latest version of Apache using dnf the command:

sudo dnf install httpd httpd-tools

You can start the httpd service and configure it to run on startup by entering the following commands:

sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd

To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https 
sudo firewall-cmd --reload

For additional resources on installing Apache, read the post below:

Step 3. Installing MariaDB.

By default, MariaDB is available on the Rocky Linux 9 base repository. Simply install the MariaDB package by using the dnf command:

sudo dnf install mariadb-server mariadb

After the installation is completed, start the service of the Database server and then enable the same, so that it could start itself automatically with the system reboot:

sudo systemctl restart mariadb
sudo systemctl status mariadb
sudo systemctl enable mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

First, log into the MariaDB shell with the following command:

mysql

Now we create a database and user for Drupal with the following command:

MariaDB [(none)]> create database drupal_db;
MariaDB [(none)]> GRANT ALL ON drupal_db.* TO drupal@localhost IDENTIFIED BY 'your-strong-password';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

For additional resources on installing MariaDB Database, read the post below:

Step 4. Installing PHP.

PHP is a popular scripting language that powers the dynamic content of millions of websites and apps. Now we run the commands below to install PHP:

sudo dnf epel-release
sudo dnf module enable php:remi-8.1

Once Remi PHP 8.1 module is enabled, you can now install PHP 8.1 and commonly used PHP extensions as follows:

sudo dnf install php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Check and verify the installed version:

php -v

For additional resources on installing PHP, read the post below:

Step 5. Installing Drupal on Rocky Linux 9.

Now run the following command below to download the latest version of Drupal from the official page:

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

Next, extract the downloaded file:

tar xvf drupal.tar.gz
mv drupal-*/ /var/www/html/drupal

We will need to change some folders permissions:

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

Also, we create additional files for a Drupal installer:

mkdir /var/www/html/drupal/sites/default/files
cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php

You will next set up the SELinux for Drupal. You will download the SELinux management tool to your server and set up the labeling for the Drupal source code. If SELinux is Enabled then Fix the SELinux labels:

sudo dnf install policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/drupal(/.*)?"
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/settings.php'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/files'
restorecon -Rv /var/www/html/drupal
restorecon -v /var/www/html/drupal/sites/default/settings.php
restorecon -Rv /var/www/html/drupal/sites/default/files
chown -R apache:apache /var/www/html/drupal

Step 6. Configure Apache for Drupal.

Now we configure the Drupal VirtualHost file using the following command below:

nano /etc/httpd/conf.d/drupal.conf

Add the following file:

<VirtualHost *:80>
     ServerName your-domain.com
     ServerAlias www.your-domain.com
     ServerAdmin admin@your-domain.com
     DocumentRoot /var/www/html/drupal/

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

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

sudo systemctl restart httpd

Step 7. Accessing Drupal Web Interface.

Once successfully installed, open your web browser and access Drupal using the URL http://your-domain.com. You will be redirected to the following page:

Install Drupal on Rocky Linux 9

Congratulations! You have successfully installed Drupal. Thanks for using this tutorial for installing Drupal Content Management System on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Drupal website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button