How to Install WordPress with LAMP in RHEL-Based Distributions

WordPress is an open source and free blogging application and a dynamic CMS (Content Management System) developed using MySQL and PHP.

It has a huge number of third-party plugins and themes. WordPress is currently one of the most popular blogging platforms available on the internet and is used by millions of people across the globe.

In this tutorial we are going to explain how to install the popular content management system – WordPress using LAMP (Linux, Apache, MySQL/MariaDB, PHP) on RHEL-based distributions such as CentOS Stream, Fedora, Rocky Linux, and AlmaLinux distributions.


Installing EPEL and Remi Repository

The installation that we will perform will be on Rocky Linux, but the same instructions also work on RHEL, CentOS Stream, Rocky Linux, and AlmaLinux distributions.

First, install and enable EPEL and Remi repository using the following commands.

------------------- On RHEL 9 Based Distributions ------------------- 
# dnf install
# dnf install

------------------- On RHEL 8 Based Distributions -------------------
# dnf install
# dnf install

------------------- On Fedora 36/35 -------------------
# dnf install
# dnf install

Since we are going to use PHP 8, we will need to reset the default PHP and enable the PHP 8 version using the following commands.

# yum install dnf-utils
# dnf module list php
# dnf module reset php
# dnf module enable php:remi-8.0
Install PHP 8 in Linux
Install PHP 8 in Linux

Installing LAMP Stack for WordPress

Now we are ready to install all the required packages related to our LAMP stack using the following command.

# yum install httpd mariadb mariadb-server php-gd php-soap php-intl php-mysqlnd php-pdo php-pecl-zip php-fpm php-opcache php-curl php-zip php-xmlrpc wget
Install LAMP Stack in Linux
Install LAMP Stack in Linux

Now that the installation is complete, we will need to start and secure our MariaDB installation.

# systemctl start mariadb
# mysql_secure_installation
Secure MariaDB in Linux
Secure MariaDB in Linux

Follow the instructions on the screen to answer the questions related to your MariaDB server security.

Then we will configure MariaDB to start automatically on system boot:

# systemctl enable mariadb

Next, we will do the same for the Apache web server:

# systemctl start httpd
# systemctl enable httpd

Creating WordPress MySQL Database

Our WordPress will require a database and a database user. To create one, simply use the following commands. Feel free to replace the database name, user, and password as per your preferences:

# mysql -u root -p
Enter password:

## Create database ##

## Creating new user ##
CREATE USER wordpress@localhost IDENTIFIED BY "secure_password";

## Grant privileges to database ##
GRANT ALL ON wordpress.* TO wordpress@localhost;

## FLUSH privileges ##

## Exit ##

Preparing WordPress Installation

Now we are ready to download the latest WordPress archive using the following wget command:

# cd /tmp && wget

Next extract the archive in our web directory:

# tar -xvzf latest.tar.gz -C /var/www/html

The above will create the following directory, which will contain our WordPress script:


Now change the ownership of that directory to user “apache” and set appropriate permissions:

# chown -R apache:apache /var/www/html/wordpress
# chmod -R 775 /var/www/html/wordpress

Next, configure the SELinux context for the directory and its contents.

# dnf install policycoreutils-python-utils
# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress(/.*)?"
# restorecon -Rv /var/www/html/wordpress

Creating Apache Virtual Host for WordPress

We will create a separate virtual host for our WordPress install. Open /etc/httpd/conf/httpd.conf with your favorite text editor:

# vi /etc/httpd/conf/httpd.conf

And add the following code at the bottom of the file and replace the marked text with the information related to your installation:

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

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

ErrorLog /var/log/httpd/tecminttest_error.log
CustomLog /var/log/httpd/tecminttest_access.log common

Save your changes and restart Apache:

# systemctl restart httpd

Installing WordPress on Website

Now we are ready to run our WordPress installation. To start the installation you can access either your server’s IP address at http://ip-address or if installing locally you can use http://localhost or if you are using a real domain, you can use the domain instead. You should see the following page:

Setup WordPress on CentOS 7
Setup WordPress on CentOS 7

When you click on Let’s Go button, you will be redirected to the next page of the installation, where you will have to enter the database details we created earlier.

WordPress Database Settings
WordPress Database Settings

When you have entered the details, click the submit button. WordPress will attempt to create its configuration file called wp-config.php. If everything is fine you should see the following page:

WordPress Installation Setup
WordPress Installation Setup

Once you click the “Run the installation” button, you will be asked to enter some details about your website: Site Title, Username, Password, and Email address.

WordPress Website Details
WordPress Website Details

When you have filled in all the required information finalize the installation by clicking the button at the bottom. Your installation is now complete. Your front page should look something like the image below:

WordPress Website View
WordPress Website View

And the WordPress dashboard looks as follows:

WordPress Admin Dashboard
WordPress Admin Dashboard

You can now start managing your WordPress website.


You have successfully completed the installation of WordPress using LAMP on CentOS 7. If you had any difficulties or questions, please submit them in the comment section below.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Leave a Reply to oscar serrano Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.