Install and configure Drupal 9 on CentOS 7

The
You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off
The

The
The

Drupal is a free open source content management platform designed to efficiently create professional content. Drupal makes it easy for you to create websites, online content and user participation in the community. 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 a CentOS 7 Linux system.

The following 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 generator : Allow content editors to design pages without engineering assistance
  • API First Architecture : Support for building robust decoupling and headless applications
  • Media Library : Makes the management of images, videos and other assets easier than ever.
  • Automatic update
  • New management interface and default theme

Install and configure Drupal 9 on CentOS 7

In this section, we will introduce the installation of dependencies required to run Drupal on CentOS 7. The web server used in this guide is Apache, but you can choose to use Nginx or any other web server. One of Drupal’s advantages is its custom level and many available plugins.

Step 1: Install the database server

Select the database server you want to use, which can be MySQL, MariaDB or PostgreSQL. In this guide, we will use the MariaDB database server.

Update and reboot the system before installing the database:

                      
                        sudo yum -y update
sudo systemctl reboot
                      
                    

Then refer to our guide on installing MariaDB on CentOS 7:

How to install MariaDB on CentOS 7

Step 2: Create a Drupal database

Drupal CMS requires a database and users to function properly. Open the MariaDB shell.

                      
                        $ mysql -u root -p
                      
                    

Create databases and users for Drupal.

                      
                        CREATE DATABASE drupal;
GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '[email protected]';
FLUSH PRIVILEGES;
q
                      
                    

Step 3: Install PHP and required extensions

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

                      
                        sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
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 the 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 the web server

In this guide, we use Apache as the Drupal web server on CentOS 7:

                      
                        sudo yum -y install httpd
                      
                    

Set PHP time zone and memory limit.

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

Start and enable the 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 the 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)
           man:apachectl(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 centos.computingforgeeks.com systemd[1]: Starting The Apache HTTP Server...
Jun 28 16:24:26 centos.computingforgeeks.com systemd[1]: Started The Apache HTTP Server.
                      
                    

Step 5: Download Drupal 9 on CentOS 7

Download Drupal 9 tarball:

                      
                        sudo yum install -y wget
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
                      
                    

Unzip the downloaded file.

                      
                        tar xvf drupal.tar.gz
                      
                    

Move the result folder to the /var/www/html directory.

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

Confirm the content of the file:

                      
                        $ 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 the 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 the ownership of the drupal directory to Apache users and groups.

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

Fix SELinux label:

                      
                        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 the Drupal website.

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

Modify the following and add it to the file-setting domain, administrator user and correct Drupal data path.

                      
                        
            
            
            
            
            
             
             
             
             
             
                          
     ServerName mysite.com
     ServerAlias www.mysite.com
     ServerAdmin [email protected]
     DocumentRoot /var/www/html/drupal/

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

Confirm the configuration syntax:

                      
                        $ sudo apachectl -t
Syntax OK
                      
                    

Restart the httpd web server.

                      
                        systemctl restart httpd
                      
                    

Step 7: Install Drupal 9 on CentOS 7

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

Choose the installation language:

Select the installation configuration file to use.

Set the database access details, as previously configured for Drupal:

Wait for it to complete:

Configure your site:

Upon completion, you will be taken to the website management console.

See Official documents For more information, see Drupal customization and other configuration options.

For https access, please check Drupal SSL configuration guide

Install on other systems:

Install Drupal 9 CMS on Ubuntu

Install Drupal 9 on CentOS 8

Reading books:

The best books for learning web development – ​​PHP, HTML, CSS, JavaScript and jQuery

The
You can support us by downloading this article in PDF format via the link below.

Download the guide in PDF format

turn off
The

The
The

Related Posts