Setting Up a LAMP Stack

Setting Up a LAMP Stack

LAMP is a popular software stack used for building and delivering web-based applications. It is built around an Linux server, an Apache Web Server, an MySQL database, and PHP. These four components serve as solutions for developers who seek to host and manage web-based content. Its flexibility and efficiency allow smaller developers to compete with commercial software development solutions.

In this walkthrough, we will build out our LAMP stack using Rocky Linux . You may also follow along using Alma Linux , CentOS or Red Hat

Update System Packages

Before we get started, we want to make sure that we have the most current packages on our system. To do that, we will retrieve packages by running the following:

sudo yum update && sudo yum upgrade

Configure Firewall

Next, we will configure our firewall settings to open ports 80 and 443 to allow HTTP and HTTPS traffic through. This will help when we install our Apache server later.

First, allow HTTP traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http

Then HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=https

Reload your firewall for your changes to take affect.

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

Install Apache

Next we will install Apache for our web server.

sudo yum install httpd -y

To activate the Apache server, run the following:

sudo systemctl enable httpd.service
sudo systemctl start httpd.service

Once completed, confirm that your Apache server is active by running the following:

sudo systemctl status httpd.service

You should see a prompt similar to this:

Apacheactive.PNG

Install MySQL

MySQL will serve as our database

sudo yum install mysql-server -y

Enable the My SQL service

sudo systemctl start mysqld

then allow it to start on boot.

sudo systemctl enable mysqld

Check the status of the MySQL service to confirm that it is active

sudo systemctl status mysqld.service

You should see a prompt similar to this:

mysqlactive.PNG

Configure Basic MySQL Security Settings

sudo mysql_secure_installation

Install PHP and associated modules

sudo yum -y install php php-pdo php-pecl-zip php-json php-common php-fpm php-mbstring php-cli php-mysqlnd wget upzip

Confirm PHP operability with Apache

We now will confirm that our Apache server is operational by creating a info.php file in Apache's root directory /var/www/html

<?php
phpinfo ();
?>

Once you save your .php file, attempt to open up the php page in a web browser by entering http://[your-IP-address]/info.php into your URL. If successful, you should see a page similar to this:

phppage.PNG

Wrap Up

Congratulations! You have just created your first LAMP stack. Now you may go and experiment with your new skill to create web content, develop web apps, and anything else your imagination can conjure.

If you have any further questions or feedback, you can contact me on LinkedIn, Twitter, or Instagram.