LEMP is an open-source web application stack used to develop web applications. The term LEMP is an acronym that represents L for the Linux Operating system, Nginx (pronounced as engine-x, hence the E in the acronym) web server, M for MySQL database, and P for PHP scripting language.
Install LEMP server on centOS 8; Through this tutorial, we will learn how to install LEMP server on centOS8.
How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack on CentOS 8
Follow the following steps to install Linux, Nginx, MySQL, PHP, or lamp stack on centOS 8 system:
- Step 1: Update the system
- Step 2: Install Nginx
- Step 3: Install the MariaDB database server
- Step 4: Install PHP-FPM
- Step 5: Test PHP
Step 1: Update the system
First of all, open terminal or command line and execute the following command into it to update the system packages:
sudo dnf update
Step 2: Install Nginx
Next, execute the following command on command line or terminal to instal Nginx web server:
sudo dnf install nginx –y
Once Nginx is successful installation, start the webserver using by executing the following command:
sudo systemctl start nginx
Further, we can configure the webserver to start on boot using the command:
sudo systemctl enable nginx
To confirm the Nginx version by running this command
nginx –v
Also. we can verify that Nginx is installed by browsing our Server’s IP address.
http://server-ip
Step 3: Install the MariaDB database server
MariaDB is a free and open-source database server that is a fork of MySQL. It became quite popular, especially after MySQL was acquired by Oracle. It ships with numerous features and optimizations such as better security and stability, additional storage engines, and overall better performance.
To install MariaDB on CentOS 8 by executing the following command on command line or terminal:
sudo dnf install mariadb-server mariadb
Once the installation is complete, start the database server as shown.
systemctl start mariadb
For best use, set MariaDB to start on boot using the command:
systemctl enable mariadb
Now, the default settings in MariaDB are quite weak and extra steps are required to harden the server. Therefore, run the script below to make additional tweaks to further secure your server.
mysql_secure_installation
To log in, to MariaDB, simply run:
sudo mysql -u root -p
Step 4: Install PHP-FPM
Execute the following command on command line or terminal to install the t PHP-FPM on CentOS 8:
sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring -y
To start it after the installation, execute:
sudo systemctl start php-fpm
Next, configure the PHP-FPM to start on boot using the command:
$ sudo systemctl enable php-fpm
Next, proceed to edit the config file using this command
Usually, PHP-FPM is set to run as an Apache user. However, we have installed Nginx and we need to configure the user to Nginx. Therefore, proceed and open the /etc/php-fpm.d/www.conf. file:
$ sudo vim /etc/php-fpm.d/www.conf
Scroll and locate the following lines:
user = apache group = apache
Now change both values to Nginx.
user = nginx group = nginx
Save and exit the configuration file. Then restart Nginx and php-fpm.
sudo systemctl restart nginx sudo systemctl restart php-fpm
Step 5: Test PHP
Execute the following command on command line or terminal to editing the root directory. And Create a sample PHP file as shown:
sudo vim /usr/share/nginx/html/info.php
Add the following PHP code inside:
<?php phpinfo(); ?>
Save and close
To see if it works, fire up your browser and browse the server’s address as shown
http://server-IP/info.php
If we don’t get to see the webpage, be sure to restart both PHP-FPM and Nginx and repeat the process.
sudo systemctl restart nginx php-fpm
Conclusion
Install LEMP server on centOS 8; Through this tutorial, we have learned how to install LEMP server on centOS8.