LEMP is a stack of programs that works together to build dynamic websites and web applications. The “L” in LEMP stands for Linux, which is your Linux VPS server, “E” stands for Nginx, where it is read as “engine-ex”, a web server application, “M” for MySQL, a database management system, and “P” for PHP, a scripting language.
The Linux operating system used for this guide is CentOS 7. Do note that all of the software installations below require you to log into your server using SSH and root access.
Nginx Installation
We will first begin with the Nginx installation. Nginx isn’t available on the default CentOS repositories. Due to that, it is necessary to install EPEL repositories, and to do so, run the following command in the terminal.
yum install epel-release -y
After the EPEL repositories installation is done, install Nginx by using the following command.
yum install nginx -y
Once the installation is complete, start Nginx using the start command, and to enable Nginx to start on system boot, use the enable command.
systemctl start nginx system enable nginx
Finally, to verify if Nginx is running on your server or not by visiting your server’s public IP address. You should be able to see a welcome page by Nginx.
MySQL Installation (MariaDB)
After Nginx, the next software for installation is the database management system, MySQL, along with the database manager, MariaDB.
By default, MariaDB is already included in the CentOS repositories. This means MariaDB could be easily installed onto the system using the yum command.
yum install mariadb-server mariadb -y
After the installation is completed, similarly to Nginx, start MariaDB using the start command, and to enable MariaDB to start on system boot, use the enable command.
systemctl start mariadb systemctl enable mariadb
After enabling MariaDB in your system, install MySQL in a more secure way using the following command.
mysql_secure_installation
After the installation of MySQL is done, MariaDB will request for the root password, which you would not have yet due to MySQL just being installed, just press enter and proceed with it. The follow-up prompt will request you to set a root password. Enter “Y” and follow the instructions for setting up the root password. After setting the root password, a list of questions regarding securities will be returned. It is recommended to press “Y” for all questions.
PHP Installation
The final software to install in the LEMP stack is PHP. The PHP version used here is version 7.3. We will first need to download and install some CentOS repository which is a requirement for PHP. Use the following commands in the terminal line by line in order to install it.
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm
By default, the php repository is disabled and we would need to enable it. Use the following commands to do so.
yum install yum-utils -y yum-config-manager –enable remi-php73
To install the PHP package, use the following command.
yum –enablerepo=remi,remi-php73 install php-fpm php-common
Any prompts regarding the installation permission, just press “Y” to proceed.
Finally, to verify if the service is working, install some of the common PHP modules using the following commands.
yum –enablerepo=remi,remi-php73 install php-opcache php-pecl-apcu php-pdo php-mysqlnd php-pgsql php-pec-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
With this, all the LEMP software installations are completed.