Serverspace Black Friday
JH
Joe Harris
October 27, 2020
Updated June 7, 2023

How to Install LAMP Stack on CentOS 8

CentOS Databases Linux Web server

Using another OS?

Select the desired version or distribution.

In this tutorial, we will install the LAMP stack on CentOS 8. LAMP is an acronym for Linux with an Apache web server, MariaDB database management system, and PHP for working with dynamic content. All actions must be performed by the root account.

In the Serverspace you can create a server with already installed app "LAMP".

Installing Apache on CentOS 8

Let’s install Apache web server.

dnf install httpd

Start the Apache daemon and make it start automatically during system boot.

systemctl start httpd
systemctl enable httpd

If you have a firewalld enabled, you must open the http or https ports, or both of them.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
systemctl reload firewalld

To test the web server symply enter the IP address of your server in the browser.

Apache test page
Screenshot 1. Apache test page.

MariaDB installation

MariaDB is an alternative for MySQL database management system. It is developed by former members of the MySQL team, since the last one can become a proprietary Oracle product.

Let’s install MariaDB DBMS.

dnf install mariadb-server

Now start the service and make it run automatically during system boot.

systemctl start mariadb
systemctl enable mariadb

To complete the basic DBMS security configuration, run the script and follow the instructions:

mysql_secure_installation

You can now enter the MariaDB command line.

mysql
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 15
Server version: 10.3.17-MariaDB MariaDB Server
...

If you see this text, MariaDB is working now.

PHP installing

The first package is PHP, and the second one allows PHP to interact with the DBMS. Let's install them.

dnf install php php-mysqlnd

Now restart Apache to enable PHP modules.

systemctl restart httpd

To test how PHP works, let’s create a file php.php in the /var/www/html/ folder.

nano /var/www/html/php.php

And insert the following lines there:

<!--?php phpinfo(); ?-->

Save and close this file. Now enter the IP address of your server in the browser and add /php.php to it. You will see PHP service information.

PHP information page
Screenshot 2. PHP information page.

Attention! Do not leave this file on the server, it is a security risk.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.