Drupal is a highly popular and versatile content management system (CMS) used by numerous organizations, including global enterprises, governments, educational institutions, and more. With its robust features, scalable architecture, and multilingual support, Drupal empowers businesses to create and manage their web content effectively. In this article, we will guide you through the process of installing Drupal CMS with Nginx on a Rocky Linux 8 server. By following these steps, you can have your Drupal website up and running in no time.
Prerequisites
Before we begin the installation process, let’s ensure that we have all the necessary prerequisites in place:
- A Rocky Linux server – In this example, we will use a Rocky Linux 8.x server with the hostname ‘drupal-server’.
- A non-root user with sudo/root administrator privileges.
- A domain name pointed to the Rocky Linux server’s IP address – This is particularly important if you are setting up the website in a production environment.
Setting up Repositories
To install the LEMP stack (Nginx, MariaDB/MySQL, and PHP-FPM) on Rocky Linux, we need to add and enable two repositories – the EPEL repository and the REMI repository.
To add the EPEL repository, run the following command:
sudo dnf install epel-release
When prompted for confirmation, enter ‘y’ and press ENTER.
Next, add the REMI repository for Rocky Linux 8.4 with the following command:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Again, enter ‘y’ to proceed.
To verify the list of available repositories on your system, run the following command:
sudo dnf repolist
You should now see the EPEL and REMI repositories added to your Rocky Linux system.
Installing Package Dependencies
Drupal can be installed with various web servers and databases. In this tutorial, we will use Nginx as the web server, MariaDB as the database server, and PHP 8.1 as the programming language.
To install the necessary package dependencies, run the following command:
sudo dnf install nginx mariadb-server php php-fpm php-cli php-devel php-mbstring php-gd php-xml php-curl php-mysqlnd php-pdo php-json php-opcache php-pear php-pecl-apcu php-pecl-crypto
When prompted for confirmation, enter ‘y’ to proceed.
After the packages are installed, start the Nginx, MariaDB, and PHP-FPM services using the following command:
sudo systemctl start nginx mariadb php-fpm
To ensure that these services start automatically at boot, enable them with the following command:
sudo systemctl enable nginx mariadb php-fpm
Setting up Firewalld
Firewalld is a firewall management tool that comes pre-installed with Rocky Linux. It is recommended to enable the firewall to ensure the security of your Drupal installation.
To allow HTTP and HTTPS traffic through the firewall, run the following commands:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload
These commands will add the necessary rules to allow clients to access your Drupal installation.
Setting up MariaDB Server
Next, we will configure the MariaDB database server for Drupal. Start by securing the MariaDB deployment using the following command:
sudo mysql_secure_installation
Follow the prompts to set up the MariaDB root password, remove anonymous users, disable remote login for the root user, remove the test database, and reload table privileges.
After securing the MariaDB deployment, log in to the MySQL/MariaDB shell as the root user:
sudo mysql -u root -p
Create a new database and user for Drupal with the following queries:
CREATE DATABASE drupaldb;
CREATE USER drupal@localhost IDENTIFIED BY 'password';
GRANT ALL ON drupaldb.* TO drupal@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
Replace ‘password’ with a strong password of your choice.
To verify the privileges for the MariaDB user, run the following query:
SHOW GRANTS FOR drupal@localhost;
Exit the MySQL/MariaDB shell by typing ‘exit’ or ‘quit’.
Installing PECL Extension: uploadprogress
The uploadprogress extension is required by Drupal to display a progress bar for file uploads. We will install it from the PECL repository.
First, check if the ‘pecl’ command is available on your system:
which pecl
If the command is available, you will see the full path of the ‘pecl’ binary file.
Install the uploadprogress extension using the following command:
sudo pecl install uploadprogress
Create a new configuration file for the uploadprogress extension:
sudo nano /etc/php.d/uploadprogress.ini
Add the following content to the file:
; configuration for php upload progress module
; priority 15
extension=uploadprogress.so
Save the file and exit the editor.
Restart the PHP-FPM service to apply the changes:
sudo systemctl restart php-fpm
Configuring PHP-FPM
Next, we will configure PHP-FPM and create a specific PHP-FPM pool for Drupal.
Open the ‘/etc/php.ini’ file using a text editor:
sudo nano /etc/php.ini
Make the following changes to the file:
memory_limit = 512M
upload_max_filesize = 60M
max_execution_time = 300
date.timezone = Europe/Stockholm
Save the file and exit the editor.
Copy the default PHP-FPM pool configuration to a new file for Drupal:
sudo cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/drupal.conf
Edit the ‘drupal.conf’ file:
sudo nano /etc/php-fpm.d/drupal.conf
Modify the following lines in the file:
[drupal]
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen = /run/php-fpm/drupal.sock
Save the file and exit the editor.
Restart the PHP-FPM service to apply the changes:
sudo systemctl restart php-fpm
Downloading Drupal Source Code
Now, let’s download the latest version of Drupal to your server.
Change the current working directory to ‘/tmp’ and download the Drupal source code:
cd /tmp
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
Extract the downloaded file and move the extracted directory to ‘/var/www/drupal’:
tar -xvf drupal.tar.gz
mv drupal-* /var/www/drupal
Change the ownership and permissions of the Drupal installation directory:
sudo chown -R nginx:nginx /var/www/drupal/
sudo chmod -R 755 /var/www/drupal/
Setting up SELinux
To ensure that SELinux is properly configured for Drupal, we need to set up the correct file labeling and additional rules for Nginx.
Install the SELinux management tool:
sudo dnf install policycoreutils-python-utils
Set up the labeling for the Drupal source code:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/drupal(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/drupal/sites/default/settings.php'
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/drupal/sites/default/files'
sudo restorecon -Rv /var/www/drupal
Allow Nginx to access networking and mail services:
sudo setsebool -P httpd_can_sendmail on
sudo setsebool -P httpd_can_network_connect on
Setting up Nginx Web Server
Now, let’s configure Nginx to serve our Drupal website.
Create a new Nginx server block configuration file:
sudo nano /etc/nginx/conf.d/drupal.conf
Add the following configuration to the file:
server {
listen 80;
server_name drupal.example.io;
return 301 https://$host$request_uri;
}
server {
listen 443 http2 ssl;
server_name drupal.example.io;
root /var/www/drupal;
ssl_certificate /etc/letsencrypt/live/drupal.example.io/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/drupal.example.io/privkey.pem;
access_log /var/log/nginx/drupal.example.io.access.log;
error_log /var/log/nginx/drupal.example.io.error.log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/[^/]+/private/ {
return 403;
}
location ~ ^(/[a-z\-]+)?/system/files/ {
try_files $uri /index.php?$query_string;
}
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri /index.php?$query_string;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
include fastcgi_params;
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php-fpm/drupal.sock;
}
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
}
Save the file and exit the editor.
Verify the Nginx configuration:
sudo nginx -t
If there are no errors, restart the Nginx service:
sudo systemctl restart nginx
Starting Drupal Installation
With the server and Nginx configured, we can now start the Drupal installation process.
Open your web browser and visit your Drupal website using the domain name you configured (e.g., https://drupal.example.io/).
You will be greeted with the Drupal installation page. Select your preferred language and click “Save and continue”.
Choose the installation profile for your Drupal installation (e.g., Standard) and click “Save and continue”.
Set up the database connection by entering the database name, username, and password we created earlier. Click “Save and continue”.
Enter the site information, including the site name, site email, and admin account details. Make sure to choose a strong password for the admin account. Click “Save and continue”.
Once the installation process is complete, you will see a confirmation message. Click “Visit your new site” to access your Drupal website.
Finishing up Drupal Installation
After the Drupal installation is complete, we need to perform some additional steps to finalize the setup.
Set the correct file labeling for the Drupal configuration file:
sudo restorecon -v /var/www/drupal/sites/default/settings.php
sudo restorecon -Rv /var/www/drupal/sites/default/files
Change the permissions of the settings.php file to make it writable:
sudo chmod 644 /var/www/drupal/sites/default/settings.php
Open the settings.php file:
sudo nano /var/www/drupal/sites/default/settings.php
Uncomment the line starting with ‘trustedhostpatterns’ and add your domain name:
$settings['trusted_host_patterns'] = [
'^drupal\.example\.io$',
];
Save the file and exit the editor.
Finally, visit the Drupal status report page to ensure that everything is working correctly. You can access the report via the following URL:
https://drupal.example.io/admin/reports/status
If all system requirements are checked and there are no errors, your Drupal installation is now complete.
Conclusion
Congratulations! You have successfully installed Drupal CMS with Nginx on your Rocky Linux 8 server. By following the step-by-step instructions in this article, you now have a fully functional Drupal website ready for customization and content creation.
Remember to regularly update and maintain your Drupal installation to ensure optimal performance and security. If you encounter any issues or require further assistance, consult the Drupal documentation or seek support from the Drupal community.
At Shape.host, we offer reliable and scalable Linux SSD VPS hosting solutions to empower businesses with efficient cloud hosting. Our services are designed to meet the needs of Drupal users and provide a secure and high-performance environment for your websites. Contact us today to learn more about how Shape.host can support your Drupal hosting needs.