How to Install Drupal CMS 11 on AlmaLinux 9

By Anurag Singh

Updated on Sep 23, 2024

How to Install Drupal CMS 11 on AlmaLinux 9

Tutorial will explain how to install Drupal CMS 11 on AlmaLinux 9 with Nginx, MariaDB and SSL.

Drupal is a powerful open-source content management system (CMS) used for building websites and applications. It is known for its flexibility, scalability, and robust features, making it suitable for a wide range of projects, from simple blogs to complex enterprise applications. Here’s an overview of Drupal, its features, and its ecosystem.

Key Features of Drupal

Flexibility and Customization:

  • Content Types: Drupal allows you to create different content types (e.g., articles, pages, blogs) with custom fields tailored to your needs.
  • Taxonomy: Use taxonomy systems to categorize and tag content, making it easier to manage and display.

Modular Architecture:

  • Drupal has a modular structure, allowing you to extend its functionality through contributed and custom modules. There are thousands of modules available, enabling features like SEO, social media integration, e-commerce, and more.

User Management:

  • Built-in user management allows you to create and manage user roles and permissions. This is ideal for collaborative environments where different users need varying levels of access.

Responsive Design:

  • Many Drupal themes are designed to be responsive out of the box, ensuring that websites look good on all devices, from desktops to mobile phones.

Robust Security:

  • Drupal has a strong focus on security, with a dedicated security team and regular updates. It also allows for granular permissions, helping to secure sensitive content.

Multilingual Support:

  • Drupal offers excellent support for multilingual websites, allowing you to create content in multiple languages and manage translations efficiently.

SEO-Friendly:

  • Drupal provides various tools and modules that help optimize your site for search engines, including clean URLs, metadata management, and XML sitemaps.

Community and Support:

  • Drupal has a large and active community of developers, designers, and users who contribute to its development and provide support through forums, documentation, and events.

This tutorial will guide you through deploying Drupal on an AlmaLinux 9 server using Nginx as the web server and MariaDB as the database backend.

Prerequisites

  • A server running AlmaLinux 9 dedicated server or KVM VPS.
  • A root or non-root user with sudo privileges.
  • A domain name pointing to your server’s IP address.
  • Basic knowledge of the command line and Linux administration.

How to Deploy Drupal CMS on AlmaLinux 9

Step 1: Update the Server

Begin by updating your server to ensure all packages are up-to-date.

sudo dnf update -y

Step 2: Install Nginx Web Server

Install Nginx, which will serve the Drupal site.

sudo dnf install nginx -y

Start and enable Nginx to run on startup.

sudo systemctl start nginx
sudo systemctl enable nginx

Step 3: Install PHP and Required Extensions

Drupal 11 requires PHP 8.3 to run. At this point of tutorial, there was no PHP 8.3 available at the time of writing this tutorials by default in AlmaLinux 9. So we have used Remi's repository to install PHP 8.3. 

Install the repository:

sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

Rest the default PHP version and install PHP 8.3 module

sudo dnf module reset php -y
sudo dnf module install php:remi-8.3 -y

Drupal requires PHP to run. Install PHP 8.3 along with the required PHP extensions.

sudo dnf install php-fpm php-cli php-mysqlnd php-json php-opcache php-xml php-gd php-mbstring php-curl php-zip php-soap -y

Edit the PHP configuration file to set cgi.fix_pathinfo to 0.

sudo vi /etc/php.ini

Locate the line cgi.fix_pathinfo and change it to:

cgi.fix_pathinfo=0

Save and close the file, then restart PHP-FPM.

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Step 4: Configure PHP-FPM

Ensure that PHP-FPM is configured to connect to the correct MariaDB socket.

Edit your PHP-FPM configuration file:

sudo vi /etc/php-fpm.d/www.conf

Set the listen.owner and listen.group directives to match the Nginx user (nginx) and group:

listen.owner = nginx
listen.group = nginx

Save and exit the file, then restart PHP-FPM:

sudo systemctl restart php-fpm

Step 5: Install MariaDB and Create a Database for Drupal

Drupal 11 required MariaDB 10.6 or higher. Install MariaDB, which will be used as the database server.

Create a MariaDB repository file:

sudo vi /etc/yum.repos.d/MariaDB.repo

Add following content:

# MariaDB 11.4 RedHatEnterpriseLinux repository list - created 2024-09-20 02:45 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/11.4/rhel/$releasever/$basearch
baseurl = https://mirrors.gigenet.com/mariadb/yum/11.4/rhel/$releasever/$basearch
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.gigenet.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

After the file is in place, install and start MariaDB with:

sudo dnf install mariadb-server -y

Start and enable MariaDB.

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure your MariaDB installation.

sudo mysql_secure_installation

Follow the prompts to set the root password and secure the database server.

Next, log in to the MariaDB shell.

sudo mysql -u root -p

Create a database and user for Drupal.

CREATE DATABASE drupaldb;
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 6: Download and Configure Drupal

Download the latest version of Drupal from the official site.

cd /var/www
sudo wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
sudo tar -xzvf drupal.tar.gz
sudo mv drupal-* drupal

Set the proper ownership and permissions.

sudo chown -R nginx:nginx /var/www/drupal

Step 7: Configure Nginx for Drupal

Create an Nginx configuration file for your Drupal site.

sudo vi /etc/nginx/conf.d/drupal.conf

Add the following configuration, replacing your_domain.com with your actual domain:

server {
    listen 80;
    server_name drupal.hnxcode.dev; # Replace with your domain name
    root /var/www/drupal; # Replace with the path to your Drupal installation
    index index.php index.html;

    # Handling static files (CSS, JS, images)
    location ~* \.(css|js|jpg|jpeg|gif|png|ico|svg|webp|ttf|woff|woff2|eot)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
        access_log off;
    }

    # Main rewrite location to handle Drupal clean URLs
    location @rewrite {
        rewrite ^ /index.php;
    }

    # PHP scripts handling
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock; # Adjust if using a different PHP-FPM pool
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # Handling front controller pattern for index.php
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Security headers and restrictions
    location ~ /\.ht {
        deny all;
    }
}

Save and exit the file.

Test the Nginx configuration and restart Nginx.

sudo nginx -t
sudo systemctl restart nginx

Step 8: Configure SELinux and Firewall

Set SELinux permissions for Nginx and PHP.

sudo setsebool -P httpd_can_network_connect on
sudo chcon -t httpd_sys_rw_content_t /var/www/drupal/sites/default -R

Allow HTTP and HTTPS traffic through the firewall.

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

Step 9: Install SSL with Let’s Encrypt on AlmaLinux 9

To secure your Drupal website with HTTPS, we'll use Let's Encrypt, a free and automated Certificate Authority (CA). Certbot is the recommended tool for obtaining and installing Let's Encrypt SSL certificates.

Install Certbot and the Nginx plugin by running the following command:

sudo dnf install certbot python3-certbot-nginx -y

Run Certbot to obtain the SSL certificate and configure Nginx automatically:

sudo certbot --nginx -d your_domain.com

Replace your_domain.com with your actual domain name. The Certbot tool will:

Ask for your email address for urgent notices.
Ask to agree to the Terms of Service.
Optionally ask if you want to share your email with the Electronic Frontier Foundation (EFF).

Certbot will then attempt to obtain an SSL certificate and automatically configure your Nginx server to use it.

Step 10: Complete Drupal Installation via Web Browser

Open your browser and navigate to https://your_domain.com.

  • Select your preferred language and click Save and continue.
  • Choose the Standard installation profile.
  • Enter your database name, username, and password set earlier.
  • Complete the installation by configuring your site name, admin username, password, and email.
 

Troubleshooting

By default translations directory doesn't exists and it need for the installation. So we need to create it manually. Also we need to set proper writable permission for certain directory and file. Execute following set of commands:

cd /var/www/drupal
mkdir -p ./sites/default/files/translations
chmod -R 777 ./sites/default/files/translations
chmod -R 777 sites/default/files/
touch ./sites/default/settings.php
chmod 777 sites/default/settings.php

Database Configuration Error

We had issue with database socket connection. We were getting SQLSTATE[HY000] [2002] Permission denied error while configuring database. We didn't find any working SELinux command to fix it. So we have set the SELinux to enforcing by setenforce 0 and the installation proceed further.

See how you can fix it or set SELinux to enforcing.

Conclusion

We've successfully seen how to install Drupal CMS 11 on AlmaLinux 9 server with Nginx, MariaDB and SSL. Your website is now ready to use, and you can start customizing it to fit your needs.