Deploy WordPress + MariaDB + PHP + Apache web server on rhel9 with easy steps

Deploy WordPress + MariaDB + PHP + Apache web server on rhel9 with easy steps

Step by step guide to deploy MariaDB + WordPress website on Rhel Linux 9.1


Pre-Setup:

I am assuming that you have

  • Configured the yum client and EPEL repository on the machine.

  • Hostname

  • Proper Network Internet connection for package installation


  1. Install Apache Web Server

  • httpd packages for the web-server
# yum install -y httpd
  • Restart the httpd.service and enable it
# systemctl enable --now httpd
  • Add http & https package in the firewall & reload the firewall service
# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --permannet --add-port=443/tcp
# firewall-cmd --reload
# firewall-cmd --list-all
  • check the selinux label object_r:httpd_sys_content_t on /var/www/html/
# ls -lZ /var/www/html
-rw-r--r--.  1 root root unconfined_u:object_r:httpd_sys_content_t:s0      405 Feb  6  2020 index.html
  • Check the HTTP web server page on the browser

Congratulations!

your apache web server is working perfectly. Let's Move further for MySQL + WordPress configuration.


  1. Install MariaDB/MySQL and WordPress

  • For this first, we have to set setup the "REMI" repository client on the yum repository for PHP packages.
💡
Check your OS version /etc/os-release before configuring the REMI repository.
# cat /etc/os-release

[root@mh1 conf]# cat /etc/os-release


NAME="Red Hat Enterprise Linux"
VERSION="9.1 (Plow)"
REDHAT_SUPPORT_PRODUCT_VERSION="9.1"
  • Setup REMI repository for RHEL 9.1
# dnf install https://repo.extreme-ix.org/remi/enterprise/remi-release-9.rpm
# yum repolist all
  • Install PHP packages (php, php-mysqlnd, php-pdo, php-gd, php-mbstring)
# yum install php php-mysqlnd php-pdo php-gd php-mbstring
  • Install MySQL/MariaDB & Restart the service
# yum install -y mariadb-server mariadb
# yum enable --now mariadb.service
  • Fresh configure your MariaDB
#  mariadb-secure-installation
  • Get into MariaDB using new login
# mysql -u root -p
password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
💡
Create a ~/.my.cnf file and write some lines
# vim ~/.my.cnf
[clients]
username=root
password=password

:wq!

Now you don't need to use -u & -p option to work with the MariaDB database.

# mysql
  • Create a new database, user and grant permission on the database.
# mysql

MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';     
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO 'admin'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILIGES;

  1. Install WordPress and configuration

  • Go to wordpress.org and download the latest WordPress suit package using wget.
# cd /var/www/html/
# wget https://wordpress.org/latest.zip
# unzip latest.zip
# rm -rf latest.zip
  • Configure /var/www/html/wordpress/wp-config-sample.php or wp-config.php configuration file
# vim /var/www/html/wordpress/wp-config-sample.php


// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** Database username */
define( 'DB_USER', 'admin' );

/** Database password */
define( 'DB_PASSWORD', 'password' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );
  • Open /etc/httpd/conf/httpd.conf file for above configuration.
# vim /etc/httpd/conf/httpd.conf

Listen 80
User apache
Group apache
ServerAdmin admin@localhost
DocumentRoot "/var/www/html/wordpress"
  • Change user:group ownership to apache user on DocumentRoot directory
# chown -R apache:apache /var/www/html/wordpress
# ls -lZ /var/www/html/wordpress
💡
NOTE: SELinux label httpd_sys_content_t & user, group ownership should look like this:- apache apache
[root@mh1 conf]# ls -lZ /var/www/html/wordpress/
total 228
-rw-r--r--.  1 apache apache unconfined_u:object_r:httpd_sys_content_t:s0      405 Feb  6  2020 filename.extention
  • Restart the httpd.service, mariadb.service one more time to update with new changes.
# systemctl restart httpd.service  mariadb.service
# systemctl enable httpd.service mariadb.service
  • Open your browser and paste this address: http://machine-ip .

  • Fill your information and login WordPress Page.

Lots of Congratulations!