What is the LAMP Stack?


The LAMP stack is a set of open-source software used for web application development. For a web application to work, it has to include an operating system, a web server, a database, and a programming language. Each layer of software is vital for creating a database-driven and dynamic website.
The name LAMP is an acronym of the following programs:
  • Linux Operating System
  • Apache HTTP Server
  • MySQL database management system
  • PHP programming language


Step-1 Launch Ec2 Instance

Step 2: Install Apache

1. To install Apache, run the following command in the terminal:

# sudo -i                                                                                 

# passwd 

# exit

# sudo apt-get update && sudo apt-get upgrade -y

# sudo apt-get install apache2 -y


2. Check if Apache is installed correctly by running the Apache service status. Use the following the command:

# sudo systemctl start apache2 

# sudo systemctl enable apache2 

# sudo systemctl status apache2 


3. Next, make sure that the UFW firewall has an application profile for Apache by typing in the following command:

# sudo ufw app list

#sudo ufw app info "Apache Full"

4. To ensure Apache is running, enter the IP address of your server in the address bar and press ENTER.

The test Apache web server page should display as below.

Step-3: Install Mysql and Create a Database

1.To install MySQL, type in the following command:

# sudo apt-get install mysql-server -y 

# sudo mysql_secure_installation

Step 4: Install PHP

1. You create online repository, following the commands:

# sudo apt-add-repository ppa:ondrej/php

Then,Enter

# sudo apt-get install php php-mysql libapache2-mod-php  -y 

2. Next, you should modify the way Apache serves files when directories are requested. By default, Apache first looks for a file card named index.html. However, we want it to look for the index.php file instead

To change this, open the dir.conf file in a text editor with root privileges:

# sudo vim /etc/apache2/mods-enabled/dir.conf

In the configuration file, you will see the information as in the image below:


Then, move the PHP index file to the first position:


3. Press Esc :wq! to save and close the file. 

Step 5: Test PHP Processing on Web Server

1. Create a basic PHP script and save it to the “web root” directory. This is necessary for Apache to find and serve the file correctly. This directory is located at /var/www/html/.

To create a file in that directory, type in the following command:

# sudo vim /var/www/html/info.php

This command opens the bank file.

2. Inside the file, type in the valid PHP code:

<?php phpinfo (); ?>

3. Press Esc :wq! to save and close the file. 

Open a browser and type in your IP address/info.php


Step 6: Install and Configure PhpMyAdmin

# sudo apt-get install phpmyadmin -y

# sudo apt-get install php-mbstring php-gettext -y

# sudo vim /etc/apache2/apache.conf

Go to the last line,Do entry 

Include /etc/phpmyadmin/apache.conf

Press Esc :wq! to save and close the file. 

# sudo systemctl restart apache2 

You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin:

https://domain_name_or_IP/phpmyadmin


You can now log into the interface using the root username and the administrative password you set up during the MySQL installation.

When you log in, you’ll see the user interface, which will look something like this: