LEMP is a popular software stack. LEMP is named after the first letter of four software that forms the Stack i.e. Linux, Nginx, MySQL and PHP. LEMP is used to deploy PHP based web applications with MySQL database backend. LEMP is a variation of original LAMP stack, where Apache HTTP Server is replaced by Nginx Web Server.
In this article, we will install LEMP stack on RHEL 8 server. To achieve this goal, we are installing MariaDB database, Nginx web server and PHP language support on a Red Hat Enterprise Linux (RHEL) 8 server.
This Article Provides:
Environment Specification:
We have installed a Red Hat Enterprise Linux (RHEL) 8 virtual machine with following specifications.
- CPU - 3.4 Ghz (2 cores)
- Memory - 2 GB
- Storage - 20 GB
- Hostname - rhel-8-lemp.example.com
- IP Address - 192.168.116.165/24
- Operating System - Red Hat Enterprise Linux (RHEL) 8
We have also configured a Local YUM/DNF repository on our RHEL 8 server, so we can install required software without an active Red Hat subscription.
Installing MariaDB 10.3 Database on RHEL 8 Server:
Connect with rhel-8-lemp.example.com using ssh as root user.
MariaDB Server 10.3 is available in RHEL 8 local AppStream repository. Therefore, we can install it easily using dnf command.
[root@rhel-8-lemp ~]# dnf install -y mariadb-server
...
Installed:
mariadb-server-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
mariadb-backup-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
mariadb-gssapi-server-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
mariadb-server-utils-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
perl-IO-Socket-IP-0.39-5.el8.noarch
perl-IO-Socket-SSL-2.060-2.el8.noarch
perl-Mozilla-CA-20160104-7.el8.noarch
mariadb-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
mariadb-common-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
mariadb-connector-c-3.0.7-1.el8.x86_64
mariadb-connector-c-config-3.0.7-1.el8.noarch
mariadb-errmsg-3:10.3.11-1.module+el8+2765+cfa4f87b.x86_64
perl-DBD-MySQL-4.046-2.module+el8+2515+0650e81c.x86_64
perl-DBI-1.641-2.module+el8+2701+8f20fb82.x86_64
perl-Digest-1.17-395.el8.noarch
perl-Digest-MD5-2.55-396.el8.x86_64
perl-Net-SSLeay-1.85-6.el8.x86_64
perl-URI-1.73-3.el8.noarch
perl-libnet-3.11-3.el8.noarch
perl-Carp-1.42-396.el8.noarch
perl-Data-Dumper-2.167-399.el8.x86_64
perl-Encode-4:2.97-3.el8.x86_64
perl-Errno-1.28-416.el8.x86_64
perl-Exporter-5.72-396.el8.noarch
perl-File-Path-2.15-2.el8.noarch
perl-File-Temp-0.230.600-1.el8.noarch
perl-Getopt-Long-1:2.50-4.el8.noarch
perl-HTTP-Tiny-0.074-1.el8.noarch
perl-IO-1.38-416.el8.x86_64
perl-MIME-Base64-3.15-396.el8.x86_64
perl-Math-BigInt-1:1.9998.11-5.el8.noarch
perl-Math-Complex-1.59-416.el8.noarch
perl-PathTools-3.74-1.el8.x86_64
perl-Pod-Escapes-1:1.07-395.el8.noarch
perl-Pod-Perldoc-3.28-396.el8.noarch
perl-Pod-Simple-1:3.35-395.el8.noarch
perl-Pod-Usage-4:1.69-395.el8.noarch
perl-Scalar-List-Utils-3:1.49-2.el8.x86_64
perl-Socket-4:2.027-2.el8.x86_64
perl-Storable-1:3.11-3.el8.x86_64
perl-Term-ANSIColor-4.06-396.el8.noarch
perl-Term-Cap-1.17-395.el8.noarch
perl-Text-ParseWords-3.30-395.el8.noarch
perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch
perl-Time-Local-1:1.280-1.el8.noarch
perl-Unicode-Normalize-1.25-396.el8.x86_64
perl-constant-1.33-396.el8.noarch
perl-interpreter-4:5.26.3-416.el8.x86_64
perl-libs-4:5.26.3-416.el8.x86_64
perl-macros-4:5.26.3-416.el8.x86_64
perl-parent-1:0.237-1.el8.noarch
perl-podlators-4.11-1.el8.noarch
perl-threads-1:2.21-2.el8.x86_64
perl-threads-shared-1.58-2.el8.x86_64
psmisc-23.1-3.el8.x86_64
Complete!
Enable and start MariaDB service.
[root@rhel-8-lemp ~]# systemctl enable mariadb.service
Created symlink /etc/systemd/system/mysql.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service â /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.
[root@rhel-8-lemp ~]# systemctl start mariadb.service
Configure and secure MariaDB database instance.
[root@rhel-8-lemp ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
Installing Nginx Web Server 1.14 on RHEL 8:
Nginx 1.14 is available in local AppStream repository. Therefore, we can install it using dnf command.
[root@rhel-8-lemp ~]# yum install -y nginx
...
Installed:
nginx-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
gd-2.2.5-6.el8.x86_64
jbigkit-libs-2.1-14.el8.x86_64
libX11-1.6.7-1.el8.x86_64
libX11-common-1.6.7-1.el8.noarch
libXau-1.0.8-13.el8.x86_64
libXpm-3.5.12-7.el8.x86_64
libjpeg-turbo-1.5.3-7.el8.x86_64
libtiff-4.0.9-13.el8.x86_64
libwebp-1.0.0-1.el8.x86_64
libxcb-1.13-5.el8.x86_64
nginx-all-modules-1:1.14.1-8.module+el8+2505+fe936cef.noarch
nginx-filesystem-1:1.14.1-8.module+el8+2505+fe936cef.noarch
nginx-mod-http-image-filter-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
nginx-mod-http-perl-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
nginx-mod-http-xslt-filter-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
nginx-mod-mail-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
nginx-mod-stream-1:1.14.1-8.module+el8+2505+fe936cef.x86_64
dejavu-fonts-common-2.35-6.el8.noarch
dejavu-sans-fonts-2.35-6.el8.noarch
fontconfig-2.13.1-3.el8.x86_64
fontpackages-filesystem-1.44-22.el8.noarch
Complete!
Enable and start Nginx service.
[root@rhel-8-lemp ~]# systemctl enable nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service â /usr/lib/systemd/system/nginx.service.
[root@rhel-8-lemp ~]# systemctl start nginx.service
Allow HTTP service in Linux firewall.
[root@rhel-8-lemp ~]# firewall-cmd --permanent --add-service=http
success
[root@rhel-8-lemp ~]# firewall-cmd --reload
success
Browse URL http://rhel-8-lemp.example.com in a client's browser.
Nginx web server is installed and working fine on RHEL 8.
Installing PHP 7.2 on RHEL 8:
PHP 7.2 is available in local AppStream repository. Therefore, we can install it using dnf command.
[root@rhel-8-lemp ~]# dnf install -y php php-mysqlnd php-pdo php-gd php-mbstring php-fpm
...
Installed:
php-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-fpm-7.2.11-1.module+el8+2561+1aca3413.x86_64
php-gd-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-mbstring-7.2.11-1.module+el8+2561+1aca3413.x86_64
php-mysqlnd-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-pdo-7.2.11-1.module+el8+2561+1aca3413.x86_64
apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64
apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64
httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch
httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64 mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64
php-cli-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-common-7.2.11-1.module+el8+2561+1aca3413.x86_64
mailcap-2.1.48-3.el8.noarch redhat-logos-httpd-80.7-1.el8.noarch
Complete!
Edit php-fpm configurations.
[root@rhel-8-lemp ~]# vi /etc/php-fpm.d/www.conf
Find and set following settings therein.
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
Start and enable php-fpm service.
[root@rhel-8-lemp ~]# systemctl enable php-fpm.service
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service.
[root@rhel-8-lemp ~]# systemctl start php-fpm.service
Restart Nginx service to integrate PHP with Nginx.
[root@rhel-8-lemp ~]# systemctl restart nginx.service
Create a PHP file to check information about installed PHP modules.
[root@rhel-8-lemp ~]# echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php
Browse URL http://rhel-8-lemp.example.com/info.php in a client's browser.
PHP 7.2 has been installed and running on RHEL 8.
We have successfully installed LEMP stack on RHEL 8 server.
0 Comments