How to Install LAMP Stack on CentOS 8

Install LAMP Stack on CentOS 8

In this article, we will have explained the necessary steps to install and configure LAMP Stack on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

LAMP is short for Linux, Apache, MySQL or PHP which is an open source web development platform. It uses Linux as it’s operating system while Apache and MySQL are used as a web & database servers, the PHP is also used as an object oriented scripting language to work as a complete web stack, which is used to prepare servers for hosting web content.

Install LAMP Stack on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Apache.

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

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

Check Apache version:

Step 3. Install MariaDB.

Run the following command as root or user with sudo privileges to install MariaDB on CentOS 8:

Once MariaDB server is installed, start and enable the service with:

MariaDB server package comes with a script called mysql_secure_installation performs several security-related operations, and sets the root password:

Secure-MariaDB-Linux-Server

Step 4. Installing PHP.

Add remi repository in CentOS so we can install latest PHP 7.3, typing following command:

The default PHP module is set to PHP 7.3. To install a newer PHP release, enable the appropriate version:

Then, that we have Remi repository enabled, we can install PHP and several most common PHP modules with:

Step 5. Configure FirewallD.

By default, CentOS 8 forbids public access to port 80. To allow other computers to access the web page, we need to open port 80 in firewalld, the dynamic firewall manager on CentOS. Run the following command to open port 80:

Step 6. Confirm the LAMP server installation.

Create a file called info.php within the /var/www/html/ directory with the following content:

Now open your browser to the http://localhost/info.php, You will see the PHP information which indicates you have installed and configured Apache, MariaDB and PHP on your CentOS 8 server.

That’s all you need to do to Install LAMP Stack on CentOS 8. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.