Install LAMP Stack on CentOS 8

0
172

This guide describes a step by step tutorial on how to install LAMP stack on CentOS 8.

Install LAMP Stack on CentOS 8

LAMP is a group of opensource web development softwares; Linux OS, Apache http server, MariaDB/MySQL relational database management systems and PHP web scripting language.

Run system package update.

dnf update

Install CentOS 8 Linux System

In this case, the first component of the LAMP stack is our CentOS 8 Linux system. To install CentOS 8, see our guide on how to install it on VirtualBox by following the link below;

Install CentOS 8 on VirtualBox

Install Apache HTTP Server on CentOS 8

Apache http server can be installed on CentOS 8 as easily as running the command below;

dnf install httpd

Running Apache

Once the installation is done, you can start and enable Apache to run on system reboot by executing;

systemctl enable --now  httpd

To check the status;

systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-07 13:59:33 EDT; 42s ago
     Docs: man:httpd.service(8)
 Main PID: 26699 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 11512)
   Memory: 24.8M
   CGroup: /system.slice/httpd.service
           ├─26699 /usr/sbin/httpd -DFOREGROUND
           ├─26700 /usr/sbin/httpd -DFOREGROUND
           ├─26701 /usr/sbin/httpd -DFOREGROUND
           ├─26702 /usr/sbin/httpd -DFOREGROUND
           └─26703 /usr/sbin/httpd -DFOREGROUND
...

To verify if it is enabled to run on boot, run the command below. The output should enabled;

systemctl is-enabled httpd

Allow Apache Through the FirewallD

To enable external access to Apache web server, you need to allow web traffic on FirewallD. If you are serving just HTTP traffic, just open port 80/tcp otherwise, open port 443/tcp

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

Testing Apache

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

Install LAMP Stack on CentOS 8

Install MariaDB Database Server on CentOS 8

Install MariaDB on CentOS 8 with the command;

dnf install mariadb-server

This installs MariaDB 10.3.

mysql -V
mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1

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 also use 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 MySQL PHP module on CentOS 8 by running the command;

dnf install php 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

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 /var/www/html/test.php
<?php 
phpinfo(); 
?>

Restart Apache

systemctl restart httpd

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

PHP on CentOS 8

There you go, Your LAMP stack is installed on CentOS 8 and is ready for your web development tasks.

Be sure to remove PHP test page.

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

Related Tutorials

Install LAMP Stack on Fedora 30

How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28/29

Install LAMP Stack with MariaDB 10 on Debian 10 Buster

Install LAMP Stack on Debian 9

LEAVE A REPLY

Please enter your comment!
Please enter your name here