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.
Also, you can read How to install the LAMP stack on Oracle Linux 8 / RHEL 8 / CentOS8?
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
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:
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
Then, start and enable the
:~# 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
group parameters. You will find it with the value of
apache, change it to
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
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.
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
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.
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.
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.