A LEMP Stack is a group of open source software commonly used for hosting dynamic websites and web apps. LEMP is an acronym for Linux operating system, Nginx web server, MySQL and PHP. This guide shows you how to install a LEMP stack on a CentOS 8 server with PHP 7.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is always advisable to update your system before doing any major installation in order to get the latest version of the system packages and its dependencies.
Use the command below to update with the CentOS package manager yum.

sudo yum update

Step 1 — Installing Nginx on CentOS 8

As a non-root user, you will be required to enter the sudo password for the account in use. Enter the password and continue the installation.

Proceed to install Nginx with the command below:

sudo yum install nginx -y

The next step is to start and enable Nginx to start on boot on your system with the command below:

sudo systemctl start nginx 
sudo systemctl enable nginx

To verify your Nginx web server installation, visit your server's public IP address or localhost in your web browser. This webpage should contain the default CentOS 7 Nginx web page, which is there for informational and testing purposes.

Step 2 – Install MySQL (MariaDB)
MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL.

To install the MariaDB server package, type the command below:

sudo yum install -y mariadb-server mariadb

Enable MariaDB to start at boot and proceed to start the daemon with the commands as shown below:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Our MySQL database is now running so the next thing to do is to run a simple security script that will remove some dangerous defaults and lock down some default access to our database system. Start the script by typing the command below:

sudo mysql_secure_installation

The script will ask a couple of questions including:

  • Current root password - Since this is a new installation of MySQL, you probably don’t have one so you can leave it blank and you will be asked if you want to set one. Type Y and proceed.
  • Remove anonymous users - Type Y or press the enter button to choose the default (which is Y).
  • Disable root login remotely - Type Y or press the enter button to choose the default (which is Y).
  • Remove test database - Type Y or press the enter button to choose the default (which is Y)

Step 3 — Installing PHP v7
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. In this case, it will run scripts, connect to our MariaDB databases for information, and deliver processed content over to our web server to display.
CentOS 8 comes with PHP 7.2. Install the PHP through PHP-FPM (FastCGI Process Manager using the YUM command.

Issue the command below:

sudo yum -y install php-fpm php-mysqlnd php-cli

We also need to make some changes to the PHP-FPM configuration as by default PHP FPM will run as user apache on port 9000, so we need to change the user to nginx and switch from TCP socket to Unix socket.Type the command to edit the www.conf file

sudo nano /etc/php-fpm.d/www.conf

Find and replace these lines:

user = apache to user = nginx

group = apache to group = nginx

listen.owner = nobody to listen.owner = nginx

listen.group = nobody to listen.group = nginx

Lastly, add the following line under listen =

listen =

Next, make the following changes to the /etc/php.ini file.

  • set cgi.fix_pathinfo to 0.

Next, make the following changes to the /etc/php-fpm.d/www.conf file.

  • Make sure the following values are UN-commented.

pm.min_spare_servers = 5

pm.max_spare_servers = 35

Save and close the file then proceed to start php-fpm and enable it on boot:

systemctl start php-fpm.service
systemctl enable php-fpm.service

To check the version of PHP installed, type the command below:

 php -v