How to Install LEMP Server on CentOS 8 in PHP MySQL?

03-Apr-2023

.

Admin

How to Install LEMP Server on CentOS 8 in PHP MySQL?

Hi Dev,

In this tute, we will discuss how to install lemp server on centos 8 in php mysql. you can understand a concept of installation lemp server on centos 8 in php. This tutorial will give you simple example of configure and install a lamp server on centos 8 using php. We will use install lemp server on centos 8 in php. Here, Creating a basic example of lemp server on centos 8 in php.

Install LEMP server on centOS 8; Through this tutorial, we will learn how to install LEMP server on centOS8.

Step 1: Update the system


Open terminal or command line and execute the following command into it to update the system packages:

sudo dnf update

Step 2: Install Nginx

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

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

Now that you have a web server up and running, you need to install a database system to be able to store and manage data for your site. We’ll install MariaDB, a community-developed fork of the original MySQL server by Oracle.

To install this software, run:

sudo dnf install mariadb-server mariadb

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

he 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

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

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: Allow Ports in Firewalld

If your system has firewalld installed ans active, you need to allow Apache ports. This will allow network users to access web application from remote systems.

The following commands will open the required ports for you.

sudo firewall-cmd --zone=public --permanent --add-service=http

sudo firewall-cmd --zone=public --permanent --add-service=https

sudo firewall-cmd --reload

Step 6: Test PHP

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

I hope it could help you...

#PHP