CentOSRHEL Based

How To Install Drupal on CentOS Stream 10

Install Drupal on CentOS Stream 10

In this tutorial, we will show you how to install Redis on CentOS Stream 10. This comprehensive guide walks you through every step of setting up Drupal on a fresh CentOS Stream 10 server, from initial system preparation to final configuration.

Drupal stands as one of the most flexible and secure content management systems available today, powering millions of websites worldwide. When combined with CentOS Stream 10’s enterprise-grade stability and security features, you create an ideal environment for hosting mission-critical web applications. Whether you’re a system administrator, web developer, or business owner looking to deploy a reliable Drupal installation, this tutorial provides the detailed instructions you need.

This guide covers the complete LAMP stack installation process, including Apache web server configuration, MariaDB database setup, PHP environment preparation, and Drupal deployment. You’ll also learn essential security hardening techniques and performance optimization strategies that ensure your Drupal site runs smoothly and securely.

Prerequisites and System Requirements

Before beginning the Drupal installation process on CentOS Stream 10, ensure your system meets the minimum requirements and that you have the necessary access privileges.

Minimum System Requirements:

  • CentOS Stream 10 server with at least 2GB RAM
  • 20GB available disk space
  • 1 CPU core (2+ cores recommended for production)
  • Root or sudo administrative access
  • Stable internet connection for package downloads

Recommended Hardware Specifications:
For production environments, consider upgrading to 4GB RAM and multiple CPU cores to handle concurrent user sessions effectively. SSD storage significantly improves database performance and overall site responsiveness.

Network and Security Considerations:
Ensure your server has a static IP address or proper DNS configuration. If working behind a firewall, verify that ports 80 (HTTP) and 443 (HTTPS) are accessible from external networks. Plan your backup strategy before proceeding with the installation.

Administrative Access Requirements:
You’ll need either root access or a user account with sudo privileges to install packages, modify system configurations, and manage services. Create a backup of important system files before making changes.

Preparing CentOS Stream 10 System

System preparation forms the foundation of a successful Drupal installation. Start by updating your CentOS Stream 10 system to ensure all packages are current and security patches are applied.

Update System Packages:

sudo dnf update -y
sudo dnf install epel-release -y
sudo dnf groupinstall "Development Tools" -y

The development tools package group includes essential utilities like gcc, make, and other compilation tools that may be needed for certain PHP extensions or modules.

Configure SELinux Settings:
CentOS Stream 10 uses SELinux by default for enhanced security. While keeping SELinux enabled is recommended, you’ll need to configure appropriate contexts for web server operations:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_execmem 1

System Locale and Time Zone Configuration:
Proper time zone configuration ensures accurate logging and scheduled tasks:

sudo timedatectl set-timezone America/New_York
sudo localectl set-locale LANG=en_US.UTF-8

Replace the time zone with your preferred location. UTF-8 locale support is essential for international character handling in Drupal.

Basic Firewall Setup:
Configure firewalld to allow necessary web traffic while maintaining security:

sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Installing Apache Web Server

Apache HTTP Server provides the web server foundation for your Drupal installation. CentOS Stream 10 includes Apache 2.4, which offers excellent performance and security features.

Install Apache Packages:

sudo dnf install httpd httpd-tools mod_ssl -y

The mod_ssl module enables HTTPS support, which is essential for secure Drupal installations.

Configure Apache for Optimal Performance:
Edit the main Apache configuration file to optimize for Drupal hosting:

sudo nano /etc/httpd/conf/httpd.conf

Add or modify these directives for better performance:

ServerTokens Prod
ServerSignature Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

Enable HTTP/2 Support:
HTTP/2 significantly improves website loading speeds. Enable the module:

sudo dnf install httpd-devel -y
echo "LoadModule http2_module modules/mod_http2.so" | sudo tee /etc/httpd/conf.modules.d/10-http2.conf
echo "Protocols h2 http/1.1" | sudo tee -a /etc/httpd/conf.d/http2.conf

Start and Enable Apache Service:

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

Test Apache Installation:
Verify Apache is running correctly by accessing your server’s IP address in a web browser. You should see the default Apache test page.

Security Hardening:
Create a custom security configuration file:

sudo nano /etc/httpd/conf.d/security.conf

Add these security directives:

Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"

Installing and Configuring MariaDB

MariaDB serves as the database backend for Drupal, storing all content, user data, and configuration information. CentOS Stream 10 includes MariaDB 10.11, which provides excellent performance and reliability.

Install MariaDB Server:

sudo dnf install mariadb-server mariadb -y

Start and Enable MariaDB Service:

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

Secure MariaDB Installation:
Run the security script to remove default accounts and set root password:

sudo mysql_secure_installation

Follow the prompts to:

  • Set root password
  • Remove anonymous users
  • Disable remote root login
  • Remove test database
  • Reload privilege tables

Create Drupal Database and User:
Access MariaDB console and create the necessary database:

sudo mysql -u root -p

Execute these SQL commands:

CREATE DATABASE drupal_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace ‘secure_password’ with a strong password containing uppercase, lowercase, numbers, and special characters.

Optimize MariaDB for Drupal:
Edit the MariaDB configuration file:

sudo vim /etc/my.cnf.d/mariadb-server.cnf

Add these optimization settings under the [mysqld] section:

[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_file_per_table = 1
innodb_flush_method = O_DIRECT
query_cache_size = 0
query_cache_type = 0

Restart MariaDB to apply changes:

sudo systemctl restart mariadb

Installing PHP and Required Extensions

PHP powers Drupal’s dynamic functionality. Install PHP 8.2 along with essential extensions required for optimal Drupal performance.

Install PHP and Core Extensions:

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

Install Additional Drupal-Specific Extensions:

sudo dnf install php-pdo php-tokenizer php-dom php-simplexml php-xmlwriter php-xmlreader php-fileinfo -y

Configure PHP Settings for Drupal:
Edit the PHP configuration file:

sudo nano /etc/php.ini

Modify these important settings:

memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 300
max_input_vars = 3000
date.timezone = America/New_York
opcache.enable = 1
opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000

Configure PHP-FPM:
Edit the PHP-FPM pool configuration:

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

Optimize these settings:

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

Start and Enable PHP-FPM:

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

Test PHP Installation:
Create a PHP info file to verify the installation:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Access http://your-server-ip/info.php to view PHP configuration details. Remove this file after testing for security.

Downloading and Preparing Drupal

Download the latest stable version of Drupal and prepare the web directory structure for installation.

Install Composer:
Composer manages PHP dependencies and is essential for modern Drupal installations:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Download Drupal Using Composer:

cd /var/www
sudo composer create-project drupal/recommended-project drupal
sudo chown -R apache:apache /var/www/drupal

Set Proper File Permissions:
Drupal requires specific file permissions for security and functionality:

sudo find /var/www/drupal -type d -exec chmod 755 {} \;
sudo find /var/www/drupal -type f -exec chmod 644 {} \;
sudo chmod -R 775 /var/www/drupal/web/sites/default/files
sudo chmod 666 /var/www/drupal/web/sites/default/settings.php

Create Apache Virtual Host:
Create a dedicated virtual host configuration for your Drupal site:

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

Add this virtual host configuration:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/drupal/web
    
    <Directory "/var/www/drupal/web">
        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>
    
    ErrorLog /var/log/httpd/drupal_error.log
    CustomLog /var/log/httpd/drupal_access.log combined
</VirtualHost>

Replace “your-domain.com” with your actual domain name or server IP address.

Restart Apache:

sudo systemctl restart httpd

Drupal Installation Process

With all prerequisites installed and configured, proceed with the Drupal web-based installation process.

Access the Web Installer:
Open your web browser and navigate to your server’s domain or IP address. The Drupal installation wizard will automatically launch.

Install Drupal on CentOS Stream 10

Select Installation Profile:
Choose from three installation profiles:

  • Standard: Includes commonly used features and modules
  • Minimal: Basic Drupal installation with minimal modules
  • Demo: Pre-configured demonstration site with sample content

For most installations, select “Standard” profile for a well-rounded starting point.

Configure Database Connection:
Enter the database credentials created earlier:

  • Database type: MySQL, MariaDB, or equivalent
  • Database name: drupal_db
  • Database username: drupal_user
  • Database password: [your secure password]
  • Host: localhost
  • Port: 3306 (default)

Advanced Database Options:
Click “Advanced options” to configure:

  • Table name prefix (optional)
  • Database connection collation

Site Information Configuration:
Complete the site setup form:

  • Site name: Your website’s title
  • Site email address: Administrative contact email
  • Username: Administrative account username
  • Password: Strong administrative password
  • Email address: Administrator’s email address
  • Default country: Your geographic location
  • Default time zone: Your preferred time zone

Installation Profile Configuration:
The Standard profile automatically enables essential modules including:

  • Content types (Article, Basic page)
  • Comment system
  • User management
  • Search functionality
  • Administrative toolbar

Handle Installation Errors:
Common installation issues and solutions:

Permission Errors:

sudo chown -R apache:apache /var/www/drupal
sudo chmod 666 /var/www/drupal/web/sites/default/settings.php

Database Connection Errors:
Verify MariaDB service status and user permissions:

sudo systemctl status mariadb
mysql -u drupal_user -p drupal_db

Memory Limit Errors:
Increase PHP memory limit in /etc/php.ini:

memory_limit = 512M

Verify Installation Success:
Upon successful installation, Drupal redirects to the homepage displaying welcome content. The administrative account gains access to all site configuration options.

Post-Installation Configuration

Secure and optimize your new Drupal installation with essential post-installation configurations.

Configure Trusted Host Settings:
Edit the settings.php file to prevent HTTP Host header attacks:

sudo nano /var/www/drupal/web/sites/default/settings.php

Add trusted host patterns:

$settings['trusted_host_patterns'] = [
  '^your-domain\.com$',
  '^www\.your-domain\.com$',
];

Set Up Cron Jobs:
Drupal requires regular cron execution for maintenance tasks:

sudo crontab -e

Add this line for hourly cron execution:

0 * * * * /usr/bin/curl -s https://your-domain.com/cron/YOUR_CRON_KEY

Find your cron key in Configuration > System > Cron.

Configure File Upload Directories:
Create additional upload directories for better organization:

sudo mkdir -p /var/www/drupal/web/sites/default/files/private
sudo chown -R apache:apache /var/www/drupal/web/sites/default/files
sudo chmod -R 775 /var/www/drupal/web/sites/default/files

Install Essential Modules:
Consider installing these popular contributed modules:

  • Admin Toolbar: Enhanced administrative interface
  • Pathauto: Automatic URL alias generation
  • Token: Provides token replacement functionality
  • Views: Advanced content listing capabilities

Configure Clean URLs:
Enable clean URLs for SEO-friendly permalinks. This should be automatically enabled with proper Apache mod_rewrite configuration.

Email Configuration:
Configure SMTP settings for reliable email delivery:

  • Install SMTP Authentication Support module
  • Configure SMTP server details in Configuration > System > Email

Performance Optimization:
Enable Drupal’s built-in caching mechanisms:

  • Navigate to Configuration > Performance
  • Enable “Cache pages for anonymous users”
  • Enable “Cache blocks”
  • Set appropriate cache maximum age

Security Best Practices

Implement comprehensive security measures to protect your Drupal installation from common threats and vulnerabilities.

File Permission Hardening:
Implement strict file permissions after installation:

sudo chmod 444 /var/www/drupal/web/sites/default/settings.php
sudo find /var/www/drupal -name "*.php" -exec chmod 644 {} \;
sudo find /var/www/drupal -type d -exec chmod 755 {} \;

Database Security Enhancements:
Regularly update database passwords and review user permissions:

ALTER USER 'drupal_user'@'localhost' IDENTIFIED BY 'new_secure_password';
FLUSH PRIVILEGES;

Apache Security Configuration:
Enhance Apache security with additional headers and restrictions:

<Directory "/var/www/drupal/web">
    Options -Indexes -ExecCGI
    AllowOverride All
    Require all granted
</Directory>

<Files "*.php">
    Require all granted
</Files>

<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$">
    Require all denied
</FilesMatch>

SSL/TLS Certificate Setup:
Secure your site with Let’s Encrypt certificates:

sudo dnf install certbot python3-certbot-apache -y
sudo certbot --apache -d your-domain.com -d www.your-domain.com

Regular Update Procedures:
Establish a routine for applying security updates:

  • Monitor Drupal security advisories
  • Test updates in staging environment
  • Apply updates during maintenance windows
  • Maintain update logs for audit purposes

Backup Strategy Implementation:
Create automated backup scripts for database and files:

#!/bin/bash
BACKUP_DIR="/backup/drupal"
DATE=$(date +%Y%m%d_%H%M%S)

# Database backup
mysqldump -u drupal_user -p'password' drupal_db > $BACKUP_DIR/database_$DATE.sql

# Files backup
tar -czf $BACKUP_DIR/files_$DATE.tar.gz /var/www/drupal/web/sites/default/files

# Remove backups older than 30 days
find $BACKUP_DIR -name "*.sql" -mtime +30 -delete
find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete

Monitoring and Logging Setup:
Configure comprehensive logging for security monitoring:

sudo vim /etc/rsyslog.conf

Add Drupal-specific logging rules and configure log rotation to manage disk space effectively.

Troubleshooting Common Issues

Address frequently encountered problems during Drupal installation and operation on CentOS Stream 10.

Permission-Related Errors:
When encountering “Permission denied” errors:

sudo chown -R apache:apache /var/www/drupal
sudo setsebool -P httpd_can_network_connect 1
sudo restorecon -R /var/www/drupal

Database Connection Issues:
Verify MariaDB service status and connection parameters:

sudo systemctl status mariadb
mysql -u drupal_user -p -h localhost drupal_db

Test connectivity and verify user privileges are correctly assigned.

PHP Configuration Problems:
Check PHP error logs for detailed error information:

sudo tail -f /var/log/php-fpm/www-error.log
sudo tail -f /var/log/httpd/error_log

Common PHP issues include insufficient memory limits, missing extensions, or incorrect file paths.

Apache Virtual Host Conflicts:
Ensure virtual host configuration doesn’t conflict with existing sites:

sudo httpd -S
sudo systemctl reload httpd

Review the output for configuration syntax errors or conflicting virtual hosts.

SELinux Troubleshooting:
When SELinux blocks web server operations:

sudo sealert -a /var/log/audit/audit.log
sudo ausearch -c 'httpd' --raw | audit2allow -M my-httpd
sudo semodule -i my-httpd.pp

Memory and Resource Limitations:
Monitor system resources and adjust PHP limits accordingly:

free -h
top -p $(pgrep php-fpm)

Increase PHP memory limits or server resources based on usage patterns.

Congratulations! You have successfully installed Drupal. Thanks for using this tutorial for installing Drupal CMS on your CentOS Stream 10 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