How to Install WordPress with LAMP Stack on CentOS 8

Table of Contents
Install WordPress with LAMP Stack on CentOS 8
WordPress is the most popular and widely used content management system or blogging platform in the world. WordPress can be used as a Blog, eCommerce platform, Portfolio Website. At the backend, WordPress uses a MySQL database for storage and works on PHP processing. WordPress provides a lot of features and these features can also be extended by using a wide variety of available plugins for it. In this tutorial, you are going to learn how to install WordPress with LAMP (Linux, Apache, MySQL, and PHP) stack on CentOS 8.
Prerequisites
Before you start to install WordPress with LAMP (Linux, Apache, MySQL, and PHP) stack on CentOS. You must have a non-root user account on your server with sudo privileges. Also, you should have:
- Apache Installed on your CentOS system using this tutorial.
- Your Domain must be pointed to your CentOS server on which you are going to install WordPress.
- You should also have installed the LetsEncrypt SSL certificate by using this tutorial.
- Install MySQL or MariaDB for the backend database.
Install PHP
Currently at the time of writing this tutorial PHP 7.2 is the latest stable version available of PHP language. If you want you can also check the latest version for installation on PHP official website.
Enable repositories by using the following commands:
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Now enable remi repo by running following command:
sudo yum-config-manager --enable remi-php72
Now to install PHP and all the required modules run below command in the terminal:
sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
You can confirm PHP installation by typing below command:
php -v
Now you should restart the apache service, you can do so by running below command:
sudo systemctl restart httpd
Create MySQL Database and Grant Permissions
You should have MySQL installed on your system if it is not installed you can install it by this tutorial.
First, log in to your MySQL database using below command:
mysql -u root -p
The above command will ask you to enter the password for the root user. Enter the password to go ahead.
Create the MySQL database for your WordPress typing below command:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now create a MySQL user and grant permissions for it using below command:
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'enter-password-here';
Now flush the database so the current MySQL version will know about these changes:
FLUSH PRIVILEGES;
Exit MySQL using below command:
EXIT;
Download and Setup WordPress
Now navigate to /tmp
directory using below command:
cd /tmp
Download the latest WordPress setup using below wget
command, you can also use curl
command here:
curl -O https://wordpress.org/latest.tar.gz
You should extract the downloaded file using below command:
tar xzvf latest.tar.gz
Now create the configuration file for WordPress using below command:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
Then copy all the files to example.com
directory using below command:
sudo cp -a /tmp/wordpress/. /var/www/example.com
Now change the ownership of example.com
directory using below command:
sudo chown -R apache: /var/www/example.com
To set up the WordPress configuration file you should generate some configuration files for it. Do so by running below command:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
The generated output keys should be:
define('AUTH_KEY', 'm=w)!7{-EEc&[email protected]/?!>_hcF*BmQ+S2Do!QP>>O-|OI21'); define('SECURE_AUTH_KEY', 'S?lk-{RG 5K~sd*1$N<aZ18jy|^0n#[email protected]#dJy2M-|jUruu[T+ cYfJ^@2-'); define('LOGGED_IN_KEY', '>i*8?IA#h/[email protected]?6MezjmoBWm&&b+h1YP?T.]Y=&*^h9[Bm`ThdbJ5zepb824LUd;-'); define('NONCE_KEY', 'cPim1L6}H1rQLtLj|FrN1DO:LZVsh`rr}5 `}k,f~%u)papX4|_J^Q%PKJ44uF[l'); define('AUTH_SALT', ',+Aa_iZ/%yj5?-0F.O>Ogd6jCLU+2_2M$+1Zo-hUog70lLa$)[email protected]<~v!Acd'); define('SECURE_AUTH_SALT', '-9sQ8iLS}1-iEX)b<A6(JNuPIGv2SV5ZiHV])[email protected]$4{[email protected]*fj8[ *Uc-'); define('LOGGED_IN_SALT', 'K$i5b^g?TK4M|w;mqlh>m9ZJ5eVAq0X;we}jvw:JNkKm-O|-=GdH-{I><`J(ZgKB'); define('NONCE_SALT', 'c_VY?z=E}2r0A&r!F/qk*rtM3>K-Id+z*qG*^2g#4/-sR2%GP>b|{<97nL4uP8K/');
Now open the /var/www/example.com/wp-config.php
file,
sudo nano /var/www/example.com/wp-config.php
Find below the section and replace it with the above data:

Now you should also update configuration file as given below for database connection by replacing password-you-provided
with the password you entered in above instructions:
define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password-you-provided'); define('FS_METHOD', 'direct');
Configure Apache
Now create and open /etc/apache/conf.d/example.com.conf
file using below command:
sudo nano /etc/apache/conf.d/example.com.conf
And paste the following code in the above file:
ServerName example.com Redirect permanent / https://example.com/ DirectoryIndex index.html index.php DocumentRoot /var/www/example.com SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem ErrorLog ${APACHE_LOG_DIR}/example.com-error.log CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined Options FollowSymLinks AllowOverride All Require all granted
Restart Apache by using the following command:
sudo systemctl restart httpd
Test WordPress
Now open the browser and navigate to your websites URL.
It will show you below window:

Now it will also prompt you for database configuration and authentication setup. Enter the proper inputs and you will be welcome to WordPress:

Conclusion
You have successfully learned how to install WordPress with the LAMP stack on CentOS 8. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to Enable SSH on Debian 10
-
How to Install Node.js with npm on Debian 10
-
How to Add Swap Space on Debian 9
-
How to Move Cursor to End of File in Vim / Vi Text Editor
-
How to Install Skype on CentOS 7
-
How to Install Android Studio in Linux
-
How to Install Google Chrome on CentOS 7
-
How to Install Ruby on CentOS 7
-
How to Install Google Chrome on CentOS 8
-
How to Install PhpStorm on Linux Mint 19
-
Secure Apache with Let’s Encrypt SSL on Debian 9
-
17 Curl Command Examples in Linux