How To Set Up LAMP Stack On CentOS 8

Do you know how to set up the LAMP stack on CentOS 8? Today, we’ll help you do that and also learn more!

LAMP stands for Linux, Apache, MariaDB, and PHP. They are open-source resources that allow you to manage your online presence.

CentOS is a Linux-based operating system. It provides enterprise-class service managed by Red Hat Enterprise Linux (RHEL).

The LAMP stack (Linux, Apache, MySQL, and PHP) is commonly used on CentOS for several reasons:

Why use LAMP stack on CentOS

  1. Stability and security- CentOS is a Linux distribution known for its stability and long-term support. It provides a secure environment for hosting web applications, making it a reliable choice for production systems.
  2. Cost-effective- it’s a free and open-source operating system, just like the components of the LAMP stack. It’s the ideal solution for web application development and hosting.
  3. Apache web server- CentOS provides seamless integration with Apache, allowing optimal utilization of its features and capabilities.
  4. MySQL Database- offers excellent compatibility and support for MySQL, making it an ideal choice for hosting database-driven web applications.
  5. PHP scripting language- PHP is a versatile and widely adopted server-side scripting language for web development. CentOS provides a reliable and efficient environment for running PHP applications, ensuring compatibility and performance.
  6. Community support- has a large and active community of users and developers, providing access to extensive documentation, forums, and resources. This community support makes troubleshooting and finding solutions easier when using the LAMP stack on CentOS.
  7. Server Administration Tools- CentOS offers a range of server administration tools and utilities, such as yum package manager, firewalld for firewall configuration, and SELinux for enhanced security. These tools simplify the management and maintenance of the LAMP stack components on CentOS.

Before setting up the LAMP, here are some things you need:

  • A server running CentOS 8 Linux
  • A terminal window/command line (Search > terminal)
  • A user account with sudo or root privileges
  • The yum and RPM package managers are included by default.

Let’s proceed to set up the Lamp stack:

The first step is to ensure that your operating system is up-to-date. It ensures that the packages to be installed run smoothly.

To do this, use this code: 

  • sudo yum update

Once this is done, let’s install Apache, the web server.

1. Run this code to install Apache;

  • sudo yum -y install httpd
Apache Installation

That’s a confirmation that you have installed Apache. Now, configure the firewall by adding this code below:

  • sudo firewall-cmd –permanent –add-service=http

It adds a secure connection from the terminal using port 80. Start the service using this code and then the IP listed to test the web server.

  • sudo systemctl start httpd.service

2. Now that Apache is running let’s install MySQL/MariaDB. 

It helps you manage the database. Start by adding the repository. Then run the check by the below code.

Now let’s run MySQL by;

  • sudo yum –disablerepo=AppStream install -y mysql-community-server
MySQL

It’s done now; secure it by adding a password.

  • cat /var/log/mysqld.log | grep -i ‘temporary password.’
  • sudo mysql_secure_installation

Under the prompts, add the secure password and hit enter. For more security, ensure to do this too:

  • Remove anonymous users? (y)
  • Disallow root login remotely? (y)
  • Remove test database and access to it? (y)
  • Reload privilege tables now? (y)

3. Let’s now set up the PHP and restart the web server.

  • sudo yum -y install php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd wget upzip
  • sudo systemctl restart httpd.service
mysql

Once it’s running, let’s proceed to add more security to it;

  • sudo firewall-cmd –permanent –zone=public –add-service=http
  • sudo firewall-cmd –permanent –zone=public –add-service=https

Restart the firewall to apply changes.

  • sudo firewall-cmd –reload
  • sudo firewall-cmd –permanent –list-all

Now that we have updated the changes let’s test our PHP. Let’s have our first site by adding this code;

  • sudo vim /var/www/html/info.php
  • Add this code: 

<?php

phpinfo ();

?>

Save and exit the file. Test the PHP by using the web server’s IP address. 

PHP

Your PHP is ready for use.

Summing up

That’s how easy it is to set up a LAMP stack on CentOS 8. LAMP provides versatility for deploying web applications.

LAMP stack on CentOS combines the stability and security of CentOS with the robustness and flexibility of the LAMP components. 

This combination makes it an excellent choice for developing and hosting web applications, particularly for organizations prioritizing reliability, security, and compatibility with enterprise-level software.

Was this article helpful?

Related Articles

Leave A Comment?