LAMP is a popular open-source web development platform that stands for Linux, Apache, MySQL, and PHP. This acronym represents the core components of a typical Linux-based web server, and it provides a stable and reliable environment for web developers to build and deploy dynamic websites and web applications.

Advertisement

In this article, we will show you how to set up a LAMP stack on Red Hat Enterprise Linux (RHEL) and CentOS Stream 9 systems.

Prerequisites

Before you start, you need to have a freshly installed RHEL or CentOS 9 system with a root user or a user with sudo privileges. You also need to have a basic understanding of Linux commands and concepts.

Step 1: Install Apache Web Server

Apache is the most widely used web server software in the world, and it’s available in the default CentOS 9 repositories. To install Apache, run the following command as root or with sudo privileges:

sudo dnf install httpd  

Once the installation is complete, start the Apache service and enable it to start automatically at boot time:

sudo systemctl start httpd 
sudo systemctl enable httpd 

To verify that the Apache web server is working correctly, open a web browser and access the server’s IP address or hostname. You should see the default Apache web page, which confirms that the web server is up and running.

Step 2: Install MariaDB Database Server

MariaDB is a fork of the MySQL database server, and it’s included in the default CentOS 9 repositories. To install MariaDB, run the following command:

sudo dnf install mariadb-server

Once the installation is complete, start the MariaDB service and enable it to start automatically at boot time:

sudo systemctl start mariadb
sudo systemctl enable mariadb 

To secure the MariaDB installation, run the following command

mysql_secure_installation 

Step 4: Install PHP

Now that Apache and MariaDB are installed and running, we can proceed to install PHP. To do this, run the following command:

sudo dnf install php php-cli php-common php-gd php-mysqlnd php-pdo 

Step 5: Configure PHP

After installing PHP, we need to make a few configuration changes to ensure that it works correctly with Apache. Open the `php.ini` configuration file using your preferred text editor:

sudo nano /etc/php.ini 

In the file, look for the following lines and modify them as follows:


memory_limit = 256M
upload_max_filesize = 128M
post_max_size = 128M

Save and close the file.

Step 6: Test the LAMP Stack

To verify that our LAMP Stack is properly installed and configured, we will create a simple PHP script and run it through Apache.

Create a new file named `info.php` in the Apache web root directory using the following command:

sudo nano /var/www/html/info.php 

Paste the following code into the file:


<?php
    phpinfo();
?>

Save and close the file.

Now, open your web browser and navigate to `http://your-server-ip/info.php`. You should see a page displaying the PHP configuration information. If you see this page, then your LAMP Stack is up and running.

How to Setup LAMP Stack on RHEL & CentOS Stream 9
Showing PHP information on RHEL & CentOS Stream 9

Congratulations! You have successfully installed and configured a LAMP Stack on your RHEL or CentOS 9 server.

Conclusion

In conclusion, setting up a LAMP Stack on RHEL or CentOS 9 involves installing Apache, MariaDB, and PHP, and making some necessary configuration changes. With the step-by-step guide provided in this article, you can have your own LAMP Stack up and running in no time. With a LAMP Stack in place, you have all the components required to host dynamic websites and applications. It’s a flexible and scalable solution that provides the foundation for many of the websites and applications we use today. Whether you’re a seasoned system administrator or a beginner, setting up a LAMP Stack on RHEL or CentOS 9 is a great way to get started with web development and hosting.

Share.
Leave A Reply

Exit mobile version