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.
Table of Contents:
- Environment Specification
- Installing MariaDB 10.3 Database on CentOS/RHEL 8
- Installing Nginx Web Server 1.14 on CentOS/RHEL 8
- Installing PHP 7.2 on CentOS/RHEL 8
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 CentOS/RHEL 8:
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.
# dnf install -y mariadb-server
Enable and start MariaDB service.
# 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. # systemctl start mariadb.service
Configure and secure MariaDB database instance.
# 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 CentOS/RHEL 8:
Nginx 1.14 is available in local AppStream repository. Therefore, we can install it using dnf command.
# yum install -y nginx
Enable and start Nginx service.
# systemctl enable nginx.service Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service â /usr/lib/systemd/system/nginx.service. # systemctl start nginx.service
Allow HTTP service in Linux firewall.
# firewall-cmd --permanent --add-service=http success # firewall-cmd --reload success
Open URL http://rhel-8-lemp.example.com in a client'sweb browser.
Nginx web server is installed and working fine on our Linux server.
Installing PHP 7.2 on CentOS/RHEL 8:
PHP 7.2 is available in local AppStream repository. Therefore, we can install it using dnf command.
# dnf install -y php php-mysqlnd php-pdo php-gd php-mbstring php-fpm
Edit php-fpm configurations.
# 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.
# systemctl enable php-fpm.service Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service â /usr/lib/systemd/system/php-fpm.service. # systemctl start php-fpm.service
Restart Nginx service to integrate PHP with Nginx.
# systemctl restart nginx.service
Create a PHP file to check information about installed PHP modules.
# echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php
Open URL http://rhel-8-lemp.example.com/info.php in a web browser.
PHP 7.2 has been installed and running on our Linux server.
We have successfully installed LEMP stack on RHEL 8 server.
No comments:
Post a Comment