Server

How to Set Up a LAMP Stack Server

In this guide, we will walk through the step-by-step installation of the LAMP Stack, a powerful combination of open-source technologies that powers countless websites and web applications.

The name LAMP comes from the four core components it uses:

  • Linux – The operating system foundation
  • Apache – The web server software
  • MySQL/MariaDB – The database management system
  • PHP – The server-side scripting language

All LAMP components are completely open-source, which means developers and companies can use them without paying expensive licensing fees. This makes LAMP one of the most popular and cost-effective solutions for hosting dynamic websites and scalable applications.

For this tutorial, You’ll need to clone this GitHub repository into your system before starting the setup process.

https://github.com/kodekloudhub/learning-app-ecommerce

We will configure both the web server and the database server to run on a single physical or virtual machine. As part of the setup, we will also install MariaDB and run a sample application to ensure everything is working correctly.

Note: In this tutorial, I used a RHEL-based distribution. However, you might be working with Ubuntu or another Linux distribution. If that’s the case, you can easily find the corresponding package names and installation commands for Ubuntu by checking the official documentation or using a reliable package reference site.

https://command-not-found.com

Step 1: MariaDB Installation

sudo yum install -y mariadb-server

Enable mariadb service and start the service

sudo systemctl start mariadb

sudo systemctl enable mariadb

Create a database user

sudo mysql

CREATE DATABASE ecomdb;
CREATE USER 'ecomuser'@'localhost' IDENTIFIED BY 'ecompassword';
GRANT ALL PRIVILEGES ON . TO 'ecomuser'@'localhost';
FLUSH PRIVILEGES;


Now that we have downloaded the repository, let’s move forward by importing the SQL file located inside the /assets directory into our database. https://github.com/kodekloudhub/learning-app-ecommerce

Veritabanına bir SQL dosyasını yüklemek:


In this scenario, we will continue by importing an SQL file named db-load-script.sql, which I have placed under the /opt directory, into our database.

sudo mysql < /opt/db-load-script.sql

Step 2: Installing php apache packages

Install Required Packages

To run a LAMP stack, you first need to install the required components: Apache, PHP, and the PHP MySQL module.

Configure Apache Default Landing Page

By default, Apache serves index.html as the landing page. To change it to index.php, we need to edit the Apache configuration file (httpd.conf).

sudo yum install -y httpd php php-mysqlnd
sudo sed -i 's/index.html/index.php/g' /etc/httpd/conf/httpd.conf
sudo systemctl start httpd

sudo systemctl enable httpd

Step 3: Sample demo



If Git is not available on your system, install it first:

sudo yum install git -y

Install git repo on /var/www/html/

sudo git clone https://github.com/kodekloudhub/learning-app-ecommerce.git /var/www/html/

sudo sed -i 's/<ipaddress-of-your-server>/localhost/g' /var/www/html/index.php


After completing the above steps, you can access your web application:

curl http://localhost


With these steps, your LAMP Stack installation is complete, and the sample application is fully operational. You can now seamlessly run applications developed with PHP, JavaScript, and MariaDB, ensuring a stable and reliable web development environment. 🚀

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button