Sunday, April 28, 2024
HomeCentosHow to Install LAMP on CentOS 8 and RHEL 8

How to Install LAMP on CentOS 8 and RHEL 8

LAMP is an popular open source stack. It is bundle of different software. It stands for Linux, Apache, MySQL/MariaDB, and PHP, when we install all these software it means we install LAMP stack. They provide a proven set of software for delivering high-performance web applications. Each software has essential capabilities. Lamp is free and open source it is used to host dynamic PHP websites. In this article you will learn how to install LAMP on CentOS 8 and RHEL 8 machine.

Step 1: Install Apache Web Server on CentOS 8 and RHEL 8

Use below command to install apache with its necessary tools

dnf install httpd httpd-tools -y
Install Apache Web Server on CentOS 8 and RHEL 8

Once installation is complete, we need to start and enable Apache service on system boot.

systemctl start httpd
systemctl enable httpd

Now verify apache is running use below command.

systemctl status httpd

Configure firewall to allow requests on Apache web server

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

Step 2: Install PHP 8 on CentOS 8 and RHEL 8

PHP is a general-purpose scripting language especially suited to web development. It is a server side scripting language that is used to develop Static websites or Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier stood for Personal Home Pages. PHP scripts can only be interpreted on a server that has PHP installed.

In this article we will install PHP version 8.0 so You need to install EPEL and Remi repositories to install PHP on the CENTOS 8 and RHEL 8 machine.

Run following commands to install these repos.

dnf install epel-release -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

The installation is completed, run below command to check available PHP versions.

dnf module list php

We just checked available PHP versions using above command. Now we need to enable latest PHP module which is currently 8.0 so run below command and enable it.

dnf module enable php:remi-8.0 -y

Finally we are ready to install PHP version 8.0 on CentOS 8
Run below command to install PHP and its necessary modules.

dnf install php php-gd php-opcache php-mysqlnd php-curl -y

Verify PHP version using below command

php -v

Everything is looking good. Now start and enable PHP-FPM on system boot.

systemctl start php-fpm
systemctl enable php-fpm
systemctl status php-fpm

Configure SELinux for Apache to use PHP-FPM to run PHP codes.

setsebool -P httpd_execmem 1

and then restart Apache

systemctl restart httpd

Test your PHP page and settings

Create info.php file using below command

vi /var/www/html/info.php

and add below lines in this file.

<?php
phpinfo();
?>

Save changes to file and exit.

Finally open your web browser and type below URL, do not forget to replace your server ip address.

http://SERVER-IP/info.php

You should see similar page given below.

Step 3: Install MariaDB on CentOS 8 and RHEL 8

MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system (RDBMS), intended to remain free and open-source software under the GNU General Public License. It is developed by the members of MYSQL team.

Install MariaDB using below command.

dnf install mariadb mariadb-server -y

Now start and enable MariaDB service on system boot using below command.

systemctl start mariadb
systemctl enable mariadb

systemctl status mariadb

Awesome. MariaDB is running fine, now we need to secure MariaDB database engine using below command.

mysql_secure_installation

Once you execute above command a script will run and you need to perform following steps.

Enter current password for root (enter for none):
(If you did not set the password for MariaDB just press enter, you can set the password in next step)
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Congratulations! you have learned how to Install LAMP stack (Apache, MariaDB, and PHP) on CentOS 8 and RHEL 8 successfully. Now you can host your PHP based websites on your server.

You can also learn that how to install Apache Jmeter to test your websites performance.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here


spot_img

Most Popular