Install LEMP Stack on CentOS 8

|
Last Updated:
|
|

Just like LAMP Stack, LEMP Stack is a group opensource tools commonly used for developing and deploying web applications. It consists of the Linux Operating System (CentOS 8 in this case), lightweight and powerful Nginx (Engine-X) web server, MySQL/MariaDB RDBMS and the server-side scripting language, PHP.

Installing LEMP Stack on CentOS 8

Run system update

dnf update

Install Nginx on CentOS 8

Nginx is available on the default AppStream repos for CentOS 8. It can simply be installed as;

dnf install nginx

=======================================================================================================================================================
 Package                                    Arch                  Version                                               Repository                Size
=======================================================================================================================================================
Installing:
 nginx                                      x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                569 k
Installing dependencies:
 nginx-all-modules                          noarch                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 23 k
 nginx-filesystem                           noarch                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 24 k
 nginx-mod-http-image-filter                x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 34 k
 nginx-mod-http-perl                        x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 45 k
 nginx-mod-http-xslt-filter                 x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 33 k
 nginx-mod-mail                             x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 64 k
 nginx-mod-stream                           x86_64                1:1.14.1-8.module_el8.0.0+5+258f653c                  AppStream                 85 k
Enabling module streams:
 nginx                                                            1.14                                                                                

Transaction Summary
=======================================================================================================================================================
Install  8 Packages

Total download size: 877 k
Installed size: 2.0 M
Is this ok [y/N]: y

Once the installation is done, start and enable Nginx to run on system boot.

systemctl enable --now nginx

To check the status;

systemctl status nginx

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-10-09 02:57:23 EDT; 10s ago
  Process: 29029 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 29027 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 29026 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 29031 (nginx)
    Tasks: 2 (limit: 11512)
   Memory: 9.6M
   CGroup: /system.slice/nginx.service
           ├─29031 nginx: master process /usr/sbin/nginx
           └─29032 nginx: worker process
...

Allow Nginx on FirewallD

To allow external access to Nginx web server, you need to open port 80 (http) or 443 (https) depending on whether you are serving HTTP or HTTPS traffic.

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

Testing Nginx

To confirm that Nginx is ready to server HTTP content, simply open your browser and enter the server IP address as http://Server.IP. You should land on Nginx HTTP server test page.

Install LEMP Stack on CentOS 8

Install MariaDB Database Server

Install MariaDB on CentOS 8 with the command;

dnf install mariadb-server

This installs MariaDB 10.3. If you want to use MariaDB 10.4 instead, follow the link below to install MariaDB 10.4 on CentOS 8.

Install MariaDB 10.4 on CentOS 8

You can as well install MySQL 8 instead;

Install MySQL 8 on CentOS 8

Once you have installed MariaDB server, start and enable it to run on system boot.

systemctl enable --now  mariadb

Next, run the security script to disable remote root login, remove test databases, remove anonymous user accounts.

mysql_secure_installation

You can login to your MariaDB server and create your databases.

Install PHP on CentOS 8

Install PHP and the required PHP module on CentOS 8 by running the command;

dnf install php php-fpm php-mysqlnd

If you need other PHP extensions for your web applications, simply install by running;

dnf install php-EXTENSION

Replacing EXTENSION with your respective PHP module.

Want to use PHP 7.4? See the link below on how to install PHP 7.4 on CentOS 8.

Install PHP 7.4 on CentOS 8

Start and enable PHP-FPM to run on boot.

systemctl enable --now php-fpm

Testing PHP on CentOS 8

You can test PHP to confirm that is working as required as well check the version and installed modules using the simple PHP info script.

vim /usr/share/nginx/html/test.php
<?php 
phpinfo(); 
?>

Save the file and navigate to the browser and enter the address, http://<server-IP>/test.php

Installing LEMP stack on CentOS 8

Remove PHP test page after testing.

rm -rf /var/www/html/test.php

The LEMP stack is now installed on CentOS 8 server.

Related Tutorials

Install LEMP Stack with MySQL 8 on Fedora 30/Fedora 29

Install LEMP Stack on Debian 10 Buster

How to Install LEMP (Nginx,MariaDB,PHP7.2) Stack on Fedora 28 / Fedora 29

How To Setup LEMP Stack (Nginx, MariaDB, PHP 7.2) on Ubuntu 18.04

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

3 thoughts on “Install LEMP Stack on CentOS 8”

Leave a Comment