How to Install WordPress with LAMP Stack on CentOS 8

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.


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

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:


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:


Exit MySQL using below command:


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

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 directory using below command:

sudo cp -a /tmp/wordpress/. /var/www/

Now change the ownership of directory using below command:

sudo chown -R apache: /var/www/

To set up the WordPress configuration file you should generate some configuration files for it. Do so by running below command:

curl -s

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/ file,

sudo nano /var/www/

Find below the section and replace it with the above data:

How to install wordpress with LAMP stack on CentOS 7 - Configuration
How to install WordPress with LAMP stack on CentOS 8 – Configuration

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/ file using below command:

sudo nano /etc/apache/conf.d/

And paste the following code in the above file:


  Redirect permanent /

  DirectoryIndex index.html index.php
  DocumentRoot /var/www/

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/
  SSLCertificateKeyFile /etc/letsencrypt/live/
  SSLCertificateChainFile /etc/letsencrypt/live/

  ErrorLog ${APACHE_LOG_DIR}/
  CustomLog ${APACHE_LOG_DIR}/ 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:

How to install WordPress with LAMP stack on CentOS 7 - Select Language
How to install WordPress with LAMP stack on CentOS 8 – Select Language

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

How to install WordPress with LAMP stack on CentOS 7 - WordPress Home
How to install WordPress with LAMP stack on CentOS 8 – WordPress Home


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.