Muhammad Nabeel
Network and System Administrator

How to Install LAMP on CentOS 8

LAMP is a popular open source stack, it is set of different software, LAMP stands for Linux, Apache, MySQL/Mariadb, and PHP. 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 websites. In this article you will learn how to install it on CentOS 8 and RHEL 8 machine.

Step 1: Install Apache Web Server on CentOS 8

Run below command to install Apache with necessary tools

dnf install httpd httpd-tools -y

Once installation is complete, we need to start and enable apache service on system boot. to do this use below command

systemctl start httpd
systemctl enable httpd

To verify that 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

PHP is a general-purpose scripting language especially suited to web development. PHP 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 machine.

use below commands to install these repos

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

Once the installation complete, run below command to check available PHP versions.

dnf module list php

We just checked available PHP versions using above command and 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

Now 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

<?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 and you will see similar page.

http://SERVER-IP/info.php

Step 3: Install MariaDB on CentOS 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.

Run following command to install MariaDB

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

Cool 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 installed Apache, Mariadb, and PHP on CentOS 8 successfully. Now you can host your websites on your server.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x