How To Install Drupal on a Virtual Server Running CentOS 8
Drupal is a powerful, open-source content management system (CMS) that allows you to create everything from personal blogs to complex websites and applications. If you’re looking to host your own Drupal site, CentOS 8 is an excellent choice for your virtual server due to its stability and performance. In this guide, we’ll walk you through the steps required to install Drupal on CentOS 8.
Prerequisites
Before we begin, make sure you have the following:
- A CentOS 8 Virtual Private Server (VPS): You can get one from a reliable hosting provider like Greenhost.Cloud.
- Root Access: You’ll need root or sudo access to install the necessary packages.
- Basic understanding of Linux command line: We’ll be executing various commands via the terminal.
- A domain name (optional): If you want to point your domain to your new site.
Step 1: Update Your System
First, let’s ensure that your CentOS 8 system is up-to-date. Connect to your server via SSH and run the following commands:
sudo dnf update -y
sudo dnf upgrade -y
Step 2: Install Required Packages
Drupal requires a web server, a database server, and PHP to function. We will install Apache, MariaDB (a MySQL fork), and PHP along with necessary PHP extensions.
Install Apache
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
Install MariaDB
sudo dnf install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure MariaDB
Run the security script to configure security options for MariaDB:
sudo mysql_secure_installation
You’ll be prompted to set a root password and answer several security questions. It’s recommended to answer ‘Y’ (yes) to most of these options.
Install PHP and Required Extensions
sudo dnf install php php-mysqlnd php-gd php-xml php-mbstring php-json php-zip -y
Restart Apache
After installing PHP, restart your web server:
sudo systemctl restart httpd
Step 3: Create a Database for Drupal
Log into MariaDB:
sudo mysql -u root -p
Once you’re logged in, create a new 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;
Make sure to replace 'your_password'
with a strong password.
Step 4: Download and Install Drupal
Download Drupal
Navigate to the /var/www/html
directory:
cd /var/www/html
Download the latest version of Drupal:
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
Extract Drupal
tar -xzf drupal.tar.gz
mv drupal-* drupal
Set Permissions
Set the correct permissions for the Drupal directories:
sudo chown -R apache:apache /var/www/html/drupal
sudo chmod -R 755 /var/www/html/drupal
Configure SELinux (if enabled)
If SELinux is enabled, you may need to run the following commands to allow Apache to serve the files:
sudo chcon -R -t httpd_sys_rw_content_t /var/www/html/drupal
Step 5: Configure Apache
Create a new configuration file for your Drupal site:
sudo nano /etc/httpd/conf.d/drupal.conf
Add the following content to the file:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/drupal
ServerName example.com
<Directory /var/www/html/drupal>
AllowOverride All
</Directory>
ErrorLog /var/log/httpd/drupal_error.log
CustomLog /var/log/httpd/drupal_access.log combined
</VirtualHost>
Make sure to update example.com
with your actual domain name.
Enable URL Rewriting
To enable clean URLs (recommended), you need to install the mod_rewrite module and make sure it’s allowed in your configuration:
sudo dnf install mod_rewrite -y
sudo systemctl restart httpd
Step 6: Complete Drupal Installation via Web Interface
- Open your web browser and navigate to
http://your_domain_or_IP/drupal
. - Select the language and click “Save and continue”.
- Choose to “Standard” installation and click “Save and continue”.
- Enter your database information:
- Database name:
drupaldb
- Database username:
drupaluser
- Password:
your_password
- Database name:
- Click “Save and continue”, and complete the setup by following the on-screen instructions.
- Once the installation is finished, you’ll be prompted to set your site name, admin username, and password.
Step 7: Finalize
After the installation is complete, remember to remove the installation script for security reasons:
sudo rm -rf /var/www/html/drupal/install.php
Conclusion
Congratulations! You’ve successfully installed Drupal on your CentOS 8 virtual server. Explore the powerful features of Drupal, customize your site with themes and modules, and create the web presence you desire. Remember to regularly back up your site and keep your software up to date for optimal performance and security.