How to Install WordPress on RHEL 8 with Apache

WordPress is an immensely popular CMS (Content Management System) that accounts for nearly 43% of all the websites according to W3techs.com.

From powering high-traffic sites such as eCommerce, and news websites to simple blogs, WordPress has remained on top of the perch among its competitors such as Joomla, Shopify, and Wix.

WordPress is open source, and free to use. It provides tons of customizations to help you build anything you want. It allows you to build high-performance, SEO-friendly sites which are mobile responsive and easy to customize.

In this guide, we will demonstrate how to install WordPress on RHEL 8 with an Apache webserver.

Prerequisites:

Before getting started, ensure that Apache, MariaDB, and PHP are installed on RHEL 8, which collectively comprise the LAMP stack.

The latest version of WordPress requires PHP 7.4 or higher. The default AppStream repository only provides PHP 7.2 which is insecure and no longer supported. You can install the latest PHP version using the Remi repository instead. With the requirements out of the way, let us get started!

Step 1: Creating a WordPress Database

We will begin by creating the database for the WordPress installation, which is used to store all the files during and after the installation.

So, log in to the MariaDB database:

$ sudo mysql -u root -p

Once on the MariaDB shell, create the database and database user and grant all the privileges to the database user.

CREATE DATABASE wordpress_db;
GRANT ALL ON wordpress_db.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'StrongPassword';

Save the changes and exit the MariaDB prompt.

FLUSH PRIVILEGES;
exit;
Create WordPress Database
Create WordPress Database

Step 2: Download and Install WordPress in RHEL

With the WordPress database in place, the next course of action is to download and configure WordPress. At the time of publishing this guide, the latest WordPress version is 5.9.1.

To download WordPress, use the wget command to download the binary file from the official site.

$ wget https://wordpress.org/latest.tar.gz
Download WordPress in RHEL
Download WordPress in RHEL

Next, extract the tarball file:

$ tar -xvf latest.tar.gz

Next, we are going to copy the wp-config-sample.php file to wp-config.php from where WordPress derives its base configuration. To do that run.

$ cp wordpress/wp-config-sample.php wordpress/wp-config.php

Next, edit the wp-config.php file.

$ vi wordpress/wp-config.php

Modify the values to correspond to your database name, database user, and password as indicated in the image shown.

WordPress Database Settings
WordPress Database Settings

Save the changes and exit the configuration file.

Next, copy the WordPress directory to the document root.

$ sudo cp -R wordpress /var/www/html/

Be sure the assign the necessary directory ownership and permissions as follows:

$ sudo chown -R apache:apache /var/www/html/wordpress
$ sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R
$ sudo chmod -Rf 775  /var/www/html

Step 3: Create Apache WordPress VirtualHost File

We also need to create a configuration file for WordPress in order to point client requests to the WordPress directory. We will create the configuration file as shown

$ sudo vi /etc/httpd/conf.d/wordpress.conf

Copy and paste the lines below to the configuration file.

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

<Directory "/var/www/html/wordpress">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>

ErrorLog /var/log/httpd/wordpress_error.log
CustomLog /var/log/httpd/wordpress_access.log common
</VirtualHost>

Save and exit the configuration file.

To apply the changes, restart Apache.

$ sudo systemctl restart httpd

Step 4: Configure SELinux for WordPress

In most cases, RHEL 8 comes with SELinux enabled. This can be a hindrance, especially during the installation of web applications. As such, we need to configure the right SELinux context to the /var/www/html/wordpress directory.

$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress(/.*)?"

For the changes to come into effect, execute:

$ sudo restorecon -Rv /var/www/html/wordpress

Then reboot your system.

NOTE: Before you reboot, ensure that Apache and MariaDB services are enabled so that they can start automatically on boot.

$ sudo systemctl enable httpd
$ sudo systemctl enable mariadb

Step 5: Finalize WordPress Installation

The last step is to complete the installation from a web browser. Launch your browser and browse your server’s IP address:

http://server-IP-address

On the first page, select your preferred installation language and click ‘Continue’.

WordPress Installation Language
WordPress Installation Language

In the next step, fill in your Site’s details.

WordPress Site Details
WordPress Site Details

Then scroll down and click ‘Install WordPress’.

WordPress Installation
WordPress Installation

And in flash, WordPress installation will be complete! To log in, click the ‘Login’ button.

WordPress Login
WordPress Login

On the login screen, provide the username and password and click ‘Log In‘.

WordPress Admin Login
WordPress Admin Login

This ushers you to the WordPress dashboard as shown. From here, you can customize your website with rich and elegant themes and plugins.

WordPress Dashboard
WordPress Dashboard

And that’s it! You have successfully installed WordPress on RHEL 8.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

2 thoughts on “How to Install WordPress on RHEL 8 with Apache”

  1. Thanks, James Kiarie, I installed wordpress in my Centos 8 Stream with MariaDB successfully.

    $ sudo restorecon -Rv /var/www/wordpress
    

    the path should be:

    $ sudo restorecon -Rv /var/www/html/wordpress
    
    Reply
  2. $ sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress R
    

    will be

    $ sudo chcon -t httpd_sys_rw_content_t /var/www/html/wordpress -R
    
    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.