When renting a VPS, to run a WordPress website you need a set of necessary software.
LEMP is a popular software group today. You must have heard the term by accident. So what is LEM?
Contents
What is LEMP?
LEMP stands for the following groups of software: Linux, NGINX (referred to as engine x), Maria DB, and PHP.
Linux is a line of operating systems. Ubutun and CentOS are two popular Linux operating systems when building VPS running WordPress websites.
NGINX is the web server software responsible for handling requests from the browser. It is a web server with good performance compared to Apache.
Maria DB is the optimized version of the MySQL database.
PHP-FPM is responsible for handling PHP code, the language used to develop WordPress websites.
In today’s article, I will show you how to install LEMP on CentOS 7.
After completing the article, you will have a complete installation of LEMP using the latest software versions such as PHP 7.
Prepare
To perform the installation steps as below you need to prepare:
- A brand new Linux server with CentOS installed. If you have not yet rented a VPS, I recommend that you choose DigitalOcean or A2Hosting .
- MobaXTerm software to connect to the server with the root user.
- In the article I use nano editor on Linux, you need to master this tool.
Step 1: Install NGINX on CentOS 7
Because NGINX does not have a CentOS repository available, we must install the EPEL repository with the following command:
yum install epel-release -yNext we install NGINX:
yum install nginx -yThey start with Nginx with the following command:
systemctl start nginxTo make nginx run when restarting VPS you use the following command:
systemctl enable nginxTo check if Nginx has installed successfully, open a browser and access the server’s IP address. If you see the following page is successful:

Step 2 Install PHP 7.1 on CentOS 7
Your server is new so it may not have the wget utility. First you need to install it:
yum instal wget -yNow you need to install the repository containing the PHP 7.1 package
yum install yum-utils -y
yum-config-manager --enable remi-php71Next you install the PHP package:
yum --enablerepo=remi,remi-php71 install php-fpm php-commonInstall some modifier PHP modules. Later, if you need to install more, refer to the command like this:
yum --enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -yWe need to do some PHP configuration steps to increase security and work with nginx.
First you need to open php.ini with nano:
nano /etc/php.iniFind the line with cgi.fix_pathinfo , uncomment the # sign and change the value from 1 to 0.
After editing, press Ctrl + O and then enter to save and Ctrl + X to exit.
By default PHP will execute the nearest PHP file if the requested php file is not found. Configuration like this prevents unwanted PHP execution.
cgi.fix_pathinfo=0Tip : in nano you can use the keyboard shortcut Ctrl + W to find the word you want.
Next, open the file /etc/php-fpm.d/ww w.conf
nano /etc/php-fpm.d/www.confFind the line that listens it is listening to localhost with port 9000. You need to convert it to a Unix socket. That is when the PHP engine will execute PHP at this address.
listen = /run/php-fpm/php-fpm.sockNext find listen.owner and listen. group , uncomment and change the following:
listen.owner = nginx
listen.group = nginxNext, change the lines user = apache and group = apache to
user = nginx
group = nginxAfter making changes, save and exit nano. Then you restart PHP-FPM:
systemctl restart php-fpmSecure php-fpm.sock with the following 2 commands:
chmod 666 /run/php-fpm/php-fpm.sock
chown nginx:nginx /run/php-fpm/php-fpm.sockRestart php again:
systemctl restart php-fpmNGINX Bridge
Above you have configured php working nginx. The nginx side you also need to configure.
Open the file /etc/nginx/nginx.conf with nano:
nano /etc/nginx/nginx.confMake sure the following line is in the server section:
include /etc/nginx/default.d/*.conf;Exit nano. Create a new /etc/nginx/default.d/default.conf file nano:
nano /etc/nginx/conf.d/default.confCopy and paste the line of code into the open file in nano: (remember to replace your_server_ip with your server ip)
server {
listen 80;
server_name your_server_ip;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}This code will tell how nginx handles PHP code with FAST CGI.
Restart nginx:
systemctl restart nginxCheck if PHP is running or not
Create file info.php in the following location:
nano /usr/share/nginx/html/info.phpCopy and paste the following line of code into the open file in nano:
<<span style="box-sizing: inherit;">?php phpinfo(); ?></span>
You should now be able to access the following address: http://your server’s IP address/info.php. If you see the following screen then OK:

Step 3: Install Maria DB
Run the following command to install Maria DB:
yum install mariadb mariadb-serverRun Maria DB with the following command:
systemctl start mariadb.serviceRun Maria DB on VPS startup with the following command:
systemctl enable mariadb.serviceBy default, Maria DB is not very secure. You run the following command to increase the security of Maria DB.
/usr/bin/mysql_secure_installationIt will first ask you Enter current password for root. At this point you don’t have a password for root, so just type Enter.
Next it asks Set Root Password? type y and then enter a password for the root account.
For the following questions, just choose y.
Finally you restart Maria DB:
systemctl restart mariadb.serviceAt this point, you have installed LEMP for CentOS 7.
If you have any trouble, just leave a comment below .

