CentOSLinuxTutorials

How To Install LAMP Stack on CentOS 8

Install LAMP Stack on CentOS 8

In this tutorial, we will show you how to install LAMP Stack on CentOS 8. For those of you who didn’t know, LAMP (a server stack) represents a full-featured stack containing the most popular web server known as Apache, the most popular database server MariaDB and the most popular open-source web programming language known as PHP. All components are free and open-source software, and the combination is suitable for building dynamic web pages.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of LAMP Stack on a CentOS 8 server.

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install LAMP Stack on CentOS 8

Step 1. First, let’s start by ensuring your system is up-to-date.

yum clean all
yum -y update

Step 2. Installing Apache on CentOS 8.

We will be installing Apache with dnf, which is the default package manager for CentOS 8:

sudo dnf install httpd

After installing Apache services on your system, start all required services:

sudo systemctl restart httpd
sudo systemctl status httpd
sudo systemctl enable httpd

Then, allow Apache HTTP server via the firewall:

sudo firewall-cmd --add-port=80/tcp --zone=public --permanent
sudo firewall-cmd --add-port=443/tcp --zone=public --permanent
sudo firewall-cmd --reload

You can verify that Apache is really running by opening your favorite web browser and entering the URL http://your-server's-address.

Install LAMP Stack on CentOS 8

Step 3. Installing MariaDB on CentOS 8.

MariaDB is a drop-in replacement for MySQL. It is a robust, scalable, and reliable SQL server that comes with a rich set of enhancements. We will also be using yum to install MariaDB:

sudo dnf install mariadb-server

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MariaDB database):

mysql -u root -p

Then, restart the MariaDB database server and enable it to start on system start-up using:

sudo systemctl restart mariadb
sudo systemctl status mariadb
sudo systemctl enable mariadb

Step 4. Installing PHP on CentOS 8.

Finally, run the commands below to install PHP along with other good-to-have modules:

sudo dnf install php php-common php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-gd php-mbstring php-xml

Restart Apache using systemctl for the changes to take effect:

sudo systemctl restart httpd

Now, it is time to test it. Create a new file called test.php on /var/www/html and add the following:

nano /var/www/html/test.php

Add the below line in the test.php file:

<?php phpinfo(); ?>

Congratulations! You have successfully installed LAMP. Thanks for using this tutorial for installing LAMP (Apache, MariaDB, and PHP) on CentOS 8 system. For additional help or useful information, we recommend you to check the official Apache, MariaDB, and PHP website.

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button