How to Install WordPress with LEMP Stack on CentOS 7

Install WordPress with LEMP Stack on CentOS 7

WordPress is the most popular and widely used content management system or blogging platform in the world. WordPress is popularly used as a Blog, Portfolio Website, eCommerce platform etc. At the backend, WordPress uses a MySQL database for storage and works on PHP processing. In this tutorial, you are going to learn how to install WordPress with LEMP (Linux, Nginx, MySQL, and PHP) stack on CentOS 7.


Before you start to install WordPress with LEMP (Linux, Nginx, MySQL, and PHP) stack on CentOS 7. You must have a non-root user account on your server with sudo privileges. Also, you should have:

  • Nginx Installed on your CentOS 7 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 LetsEncrypt SSL certificate by using this tutorial.
  • Install MySQL or MariaDB for backend database.

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:


Install PHP on CentOS 7

At the time of writing this tutorial PHP 7.2 is the latest stable version available for PHP language. You can also check the latest version for installation on PHP official website.

Install yum-utils package using the following command:

sudo yum install yum-utils

Install epel-release package by using below command:

sudo yum install epel-release

Now import Remi repository by using the following command:

sudo yum install

Enable the Remi repository by typing:

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-fpm php-mysql php-mbstring php-xml php-gd php-cli php-json php-opcache php-curl

You can confirm PHP installation by typing below command:

php -v

Now you should restart the Nginx service by running below command:

sudo systemctl restart nginx

Download and Setup WordPress

First, navigate to /tmp directory typing below command:

cd /tmp

Download the latest WordPress setup using below wget command:


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 nginx: /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 - Configuration
How to install WordPress – 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 Nginx

Now open /etc/nginx/conf.d/ file:

sudo nano /etc/nginx/conf.d/

And paste the following code in the above file file:

server {
    listen 80;

    return 301$request_uri;

server {
    listen 443 ssl http2;

    root /var/www/html/;
    index index.php;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_trusted_certificate /etc/letsencrypt/live/;

    # log files
    access_log /var/log/nginx/;
    error_log /var/log/nginx/;

    location / { 
        try_files $uri $uri/ /index.php?$args; 

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;


Restart Nginx by using the following command:

sudo systemctl restart nginx

Test WordPress

Now open the browser and navigate to your websites URL.

It will ask you for selecting language:

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

How to install WordPress - WordPress Home
How to install WordPress – WordPress Home


You have successfully learned how to install WordPress with LEMP stack on CentOS 7. If you have any queries please don’t forget to comment out.