22.9 C
Texas
angeloma
Senior Writer and partner

How to install LEMP on CentOS 8, Oracle Linux 8 / RHEL 8 /?

In this opportunity, I am going to explain step by step how to install LEMP stack on Oracle Linux 8, RHEL 8 and CentOS 8.

LAMP vs LEMP is really Apache vs Nginx

Both software stacks, allow having a fully functional webserver. With this, you can develop and run web applications created with PHP. Obviously, if you install it on a server, they can be run from another computer on the network.

The components of LAMP are Linux – ApacheMySQL/MariaDBPHP. And they are exactly the same as in LEMP except that Nginx is preferred to Apache.

Also, you can read How to install the LAMP stack on Oracle Linux 8 / RHEL 8 / CentOS8?

- Advertisement -

Why should you?

Both web servers are very good. Too good. They are open-source, free and the user community provides good support. The detail is that Nginx performs better than Apache. Proven. However, it is less flexible in its configurations.

So let us get to work.

Install LEMP on RHEL 8, CentOS 8 and Oracle Linux 8

1) LEMP on RHEL and CentOS 8: Install Nginx

The first step is to install Nginx. So open a terminal session or connect to your server using SSH.

:~$ su
:~# dnf install nginx

1.- Install Nginx on RHEL 8, CentOS 8 and Oracle Linux 8
1.- Install Nginx on RHEL 8, CentOS 8 and Oracle Linux 8

Then you need to start the service.

:~# systemctl start nginx

It is a good idea to have it start with the system, so run this command:

:~# systemctl enable nginx

The next step is to open the ports in the Firewall so that we can use Nginx.

:~# firewall-cmd --add-port=80/tcp --permanent
success
:~# firewall-cmd --add-port=443/tcp --permanent
success
:~# firewall-cmd --reload
success

Finally, open your web browser and go to your server. http://server-ip/ you will see something like this:

2.- Nginx default page on Oracle Linux 8
2.- Nginx default page on Oracle Linux 8

So, Nginx is working.

2) Install and configure PHP

The next step is to install PHP. Both Oracle Linux and RHEL, as well as CentOS, come with PHP 7.2 in their official repositories. It is a good version to start working with. So what we have to do is install it along with some of its modules.

:~# dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring

3.- Install PHP
3.- Install PHP

Then, start and enable the php-fpm service.

:~# systemctl start php-fpm
:~# systemctl enable php-fpm

Once we have started the service, it is necessary to modify some settings to make it work with Nginx.

:~# nano /etc/php-fpm.d/www.conf

At the beginning of the file, look for the user and group parameters. You will find it with the value of apache, change it to nginx.

user = nginx
group = nginx

Then, look for the line that starts with “listen”. And verify that it is as follows.

listen = /run/php-fpm/www.sock

4.- Configuring PHP to work with nginx
4.- Configuring PHP to work with Nginx

Then, reload the php-fpm service.

:~# systemctl restart php-fpm

Now it’s time to test PHP with Nginx.

Unlike Apache, the Nginx web directory in RHEL, CentOS and Oracle Linux 8 is /usr/share/nginx/html. Then, Nginx should be made the owner of that folder.

:~# chown -R nginx:nginx /usr/share/nginx/html

Then, create a new PHP file to test.

:~# nano /usr/share/nginx/html/test.php
<?php
phpinfo();
?>

After that, restart Nginx.

:~# systemctl restart nginx

Now, open the PHP file using your web browser. http://server-ip/test.php.

5.- LEMP on RHEL, CentOS 8 and Oracle Linux is almost ready
5.- LEMP on RHEL, CentOS 8 and Oracle Linux is almost ready

So everything is working.

3) Install MariaDB

MariaDB is a pretty good database manager. It is a MySQL fork and therefore compatible with it. It is one of the open-source values. So let us install it.

:~# dnf install mariadb-server

6.- LEMP on RHEL, CentOS 8 and Oracle Linux 8 - Installing MariaDB
6.- LEMP on RHEL, CentOS 8 and Oracle Linux 8 – Installing MariaDB

Then, start and enable the service.

:~# systemctl start mariadb
:~# systemctl enable mariadb

Now it is necessary to define a password for the root user. In addition to this, the installation must be secured. For this the mysql_secure_installation script is available.

:~# mysql_secure_installation

7.- Secure the MariaDB installation
7.- Secure the MariaDB installation

After defining the root password, you will be asked some configuration questions.

Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y

Now, LEMP is complete.

Conclusion

The LEMP stack is widely used today because Nginx performs quite well with a lot of traffic. So it’s up to you to choose which one suits your needs.

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article