Instructions on how to install LEMP on Centos 7 - HOSTVN Blog

In this article, HOSTVN will guide you in detail how to install LEMP on Centos 7 - Linux Nginx, MariaDB, PHP-FPM, PhpMyAdmin.

Instructions on how to install LEMP on Centos 7

What is LEMP?

LEMP is the abbreviation commonly used to indicate the use of software Linux, Nginx, MySQL / MariaDB and PHP / PHP-FPM to create a Web server environment to help deploy websites on the Internet environment.

Install LEMP on Centos 7

If you do not know how to connect VPS via SSH, you can see the instructions below

(embed) (/ embed)

Step 1: Install Nginx and basic configuration

To facilitate editing and creating files, you can connect to VPS via SFTP according to the following instructions

(embed) (/ embed)

1. Turn off Selinux

To turn off Selinux you run the following command

2. Install Nginx

By default, installing via the CentOS repo will not be the latest version. To install the latest version of Nginx We need to create our own repo by creating a file /etc/yum.repos.d/nginx.repo with the following content

After creating the repo you run the following command to install Nginx

To check the version Nginx If you have installed it, you can use the following command


If you use Firewalld then you will need to open the port to be able to access the website

3. Basic Nginx configuration

All Nginx configuration files are located in the directory / etc / nginx


  • Backup Nginx configuration file

Before starting the configuration Nginx You should backup the configuration file so that you can restore it when necessary

After backing up the configuration file, open the file /etc/nginx/nginx.conf and delete the content inside and replace with the following content

To create dhparam you run the following 2 commands

4. Start Nginx

After you have finished configuring Nginx, start Nginx

  • Check nginx configuration

Before starting Nginx, you can check if the configuration has any errors by running the following command



Step 2: Install MariaDB

MariaDB is an open source product separated from the open source by the developer community of the relational database management system MySQL in the direction of not having to pay fees with the GNU GPL. MariaDB was developed with the lead of the original developers of MySQL, due to concerns over MySQL being acquired by Oracle Corporation.

MariaDB oriented to maintain high compatibility with MySQL, to ensure library support and to best integrate with MySQL APIs and commands.

In this tutorial HOSTVN will guide you to install MariaDB instead of Mysql. By default, CentOS repo is only available for MariaDB 5. To install MariaDB 10 you need to create your own repo.

1. Create a MariaDB 10 installation repo

You create the file /etc/yum.repos.d/mariadb.repo with the following content

2. Install MariaDB

To install MariaDB, run the following command

3. Set the root password

After installing MariaDB you proceed to set the root password by running the following 2 commands

Enter current password for root (enter for none): Hit the Enter key
Switch to unix_socket authentication (Y / n): n
Change the root password? (Y / n): Y
New password: Enter the root password you want to create
Re-enter new password: Retype the root password
Remove anonymous users? (Y / n): Y
Disallow root login hack? (Y / n): Y
Remove test database and access to it? (Y / n): Y
Reload privilege tables now? (Y / n): Y

Step 3: Install PHP-FPM and the necessary Modules

1. Install PHP-FPM

To install PHP-FPM you run the following commands

2. Configure basic php parameters

All necessary php configuration will be in the file /etc/php.ini. Some basic parameters you can edit as follows

; date.timezone =
expose_php = On
short_open_tag = Off
; max_input_vars = 1000
disable_functions =

You revise it as follows:

date.timezone = Asia / Ho_Chi_Minh
expose_php = Off
short_open_tag = On
max_input_vars = 3000
disable_functions = exec, system, passthru, shell_exec, proc_close, proc_open, dl, popen, show_source, posix_kill, posix_mkfifo, posix_getpwuid, posix_setpgid, posix_setsid, posix_setuid, posix_setgid, posix_sete_ixu

3. Configure PHP-FPM

All PHP-FPM configuration files will be in the directory /etc/php-fpm.d. First, back up the default configuration file

Then open the file /etc/php-fpm.d/www.conf delete all content inside and replace with the following content

4. Start PHP-FPM

After configuration is complete, run the following 2 commands to start PHP-FPM

5. Checking PHP-FPM

After you have started PHP-FPM, you can check if it works. First you open the file /etc/nginx/conf.d/default.conf delete all content inside and replace with the following content:

Reboot Nginx to reload the configuration

Then you create the file /usr/share/nginx/html/info.php with the following content:

Proceed to access by link ip-vps / info.php To test.

Screenshot_119 - install LEMP on Centos 7

Step 4: Install PhpMyAdmin

phpMyAdmin is a free and open source tool written in PHP for administering MySQL through a web browser. It can perform many tasks such as creating, modifying or deleting databases, tables, fields or records; execute SQL statements; or manage users and grant database access.

1. Install PhpMyAdmin

To install PhpMyAdmin, run the following commands one after the other

  • Note: Access To get the link down to the latest version
2. Configure PhpMyAdmin

The configuration file of PhpMyadmin is the file First you need to run the following command

Next open the file /usr/share/phpMyAdmin/ and edit the following parameters

- Find

Add any paragraph of characters between the single quotes. For example:

- Next add the following code

Then you need to create folders tmp for PhpMyAdmin

3. Configure security for PhpMyAdmin
  • Block directory access

You open the file /etc/nginx/conf.d/default.conf delete all content and replace with the following:

  • Activate Google reCAPTCHA

To enable Google reCAPTCHA, you first need to register for a V3 API at the following link:

Screenshot_120 - install LEMP on Centos 7

Screenshot_123 - install LEMP on Centos 7


After successful registration you will be provided SITE KEY and SECRET KEY. Next you open the file /usr/share/phpMyAdmin/ and add the following 2 lines to the end of the file

Replace SITE KEY and SECRET KEY Go to, then visit ip-vps / phpmyadmin To test

Screenshot_124 - install LEMP on Centos 7



Through this article HOSTVN showed you how to install it LEMP on CentOS 7. If you have any comments or suggestions, leave a comment below. Also see the CSF Firewall Installation Guide on CentOS 7.