You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

Drupal is a free and open-source content management platform created for professional content creation in an efficient manner. Drupal enables you to create websites, online content and user engagement communities with ease. Drupal is written in PHP and it uses a database backend to store its data – MySQL, MariaDB, SQLite or PostgreSQL. This guide will show you the steps required to install and configure Drupal 9 on CentOS 7 Linux system.

Below are the minimum requirements for running Drupal 9 on CentOS 7:

  • PHP >=7.3
  • MySQL or Percona, version >=5.7.8
  • MariaDB >=10.3.7
  • PostgreSQL >=10

Some features of Drupal 9 are:

  • Layout Builder: Allows content editors to design pages without engineering help
  • API-first architecture: Enables building robust decoupled and headless applications
  • Media Library: Makes the management of images, video, and other assets easier than ever before.
  • Automated updates
  • New admin interface and default theme

Install and Configure Drupal 9 on CentOS 7

In this section we will cover installation of dependencies required to run Drupal on CentOS 7. The web server that is used in this guide is Apache but you have the option of using Nginx or any other web server. One of the good features of Drupal is its level of customization with many addons available.

Step 1: Install Database server

Choose a database server you want to use, this can be MySQL, MariaDB or PostgreSQL. In this guide we will use MariaDB database server.

Update and reboot your system before database installation:

sudo yum -y update
sudo systemctl reboot

Then refer to our guide on installation of MariaDB on CentOS 7:

How To Install MariaDB on CentOS 7

Step 2: Create Drupal Database

A database and user is required by Drupal CMS to be functional. Open MariaDB shell.

$ mysql -u root -p

Create database and user for Drupal.

GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '[email protected]';

Step 3: Install PHP and required extensions

We need to install PHP 7.3 or higher version for Drupal 9. For this installation EPEL and REMI repositories are required:

sudo yum -y install
sudo yum -y install epel-release

Enable PHP 7.3 REMI repository:

sudo yum -y install yum-utils
sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73

Install PHP 7.3 on CentOS 7:

sudo yum -y install php php-{cli,gd,mysqlnd,mbstring,json,common,dba,dbg,devel,embedded,enchant,bcmath,gmp,intl,ldap,odbc,pdo,opcache,pear,pgsql,process,recode,snmp,soap,xml,xmlrpc}

Confirm PHP version:

$ php -v
PHP 7.3.19 (cli) (built: Jun  9 2020 08:06:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.19, Copyright (c) 1998-2018 Zend Technologies

Step 4: Install Web Server

In this guide, we’ll go with Apache as Web server for Drupal on CentOS 7:

sudo yum -y install httpd

Set PHP Timezone and memory limit.

$ sudo vi /etc/php.ini
memory_limit = 256M
date.timezone = Africa/Nairobi

Start and enable httpd service.

sudo systemctl enable --now httpd

Allow http and https protocols in the firewall.

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Check if httpd service is running:

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-06-28 16:24:26 CEST; 2min 48s ago
     Docs: man:httpd(8)
  Process: 2708 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 2713 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─2713 /usr/sbin/httpd -DFOREGROUND
           ├─2714 /usr/sbin/httpd -DFOREGROUND
           ├─2715 /usr/sbin/httpd -DFOREGROUND
           ├─2716 /usr/sbin/httpd -DFOREGROUND
           ├─2717 /usr/sbin/httpd -DFOREGROUND
           └─2718 /usr/sbin/httpd -DFOREGROUND

Jun 28 16:24:26 systemd[1]: Starting The Apache HTTP Server...
Jun 28 16:24:26 systemd[1]: Started The Apache HTTP Server.

Step 5: Download Drupal 9 on CentOS 7

Download the Drupal 9 tarball:

sudo yum install -y wget
wget -O drupal.tar.gz

Extract downloaded file.

tar xvf drupal.tar.gz

Move resulting folder to /var/www/html directory.

rm -f drupal*.tar.gz
sudo mv drupal-*/  /var/www/html/drupal

Confirm file contents:

$ ls /var/www/html/drupal
autoload.php   core               INSTALL.txt  profiles    sites       vendor
composer.json  example.gitignore  LICENSE.txt  README.txt  themes      web.config
composer.lock  index.php          modules      robots.txt  update.php

Create additional directories and files required by Drupal installer.

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

Set ownership of drupal directory to Apache user and group.

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

Fix SELinux Labels:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/drupal(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/settings.php'
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/files'
sudo restorecon -Rv /var/www/html/drupal
sudo restorecon -v /var/www/html/drupal/sites/default/settings.php
sudo restorecon -Rv /var/www/html/drupal/sites/default/files

Step 6: Configure Apache for Drupal

Create a new Apache configuration for Drupal website.

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

Modify below content and add to file – set domain, admin user and correct path to Drupal data.

<VirtualHost *:80>
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/drupal/

     CustomLog /var/log/httpd/access_log combined
     ErrorLog /var/log/httpd/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]

Confirm configuration syntax:

$ sudo apachectl -t
Syntax OK

Restart httpd web server.

systemctl restart httpd

Step 7: Install Drupal 9 on CentOS 7

Open your favorite web browser to finish the installation of Drupal 9 on CentOS 7.

Choose an installation Language:

Install Drupal Ubuntu 01

Choose installation profile to be used.

Install Drupal Ubuntu 02

Set Database access details as configured earlier for Drupal:

Install Drupal Ubuntu 03

Wait for it to be completed:

Install Drupal Ubuntu 04

Configure your site:

Install Drupal Ubuntu 05

When done you’ll be directed to website administration console.

Install Drupal Ubuntu 06

Refer to the official documentation for more more reading on Drupal customizations and other configuration options.

For https access, check Drupal SSL Configuration guide

Installation on other systems:

Install Drupal 9 CMS on Ubuntu

Install Drupal 9 on CentOS 8

Books to read:

Best Books to learn Web Development – PHP, HTML, CSS, JavaScript and jQuery

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF