LAMP (Linux, Apache, MySQL, PHP) Stack-On AWS Cloud

Niket Ranjan
7 min readJul 2, 2022
LAMP STACK ON AWS EC2

This blog will guide you set up the LAMP stack web server on top of the AWS cloud and deploying an application. The prerequisite for this project, the developer already has an active AWS account.

One of the most common functions of any server is to host a website, and the most common software sets to accomplish this is referred to as a LAMP Stack.

You can set up different software stacks to accomplish your IT needs. To run a website, you will need software to make it accessible to visitors, a programming language to write it in, and a database to store information for the site. LAMP is an acronym for a specific set of software that performs these functions and helps you achieve your goal of hosting a website.

Let’s discuss each of the components used in the LAMP stack.

Linux

Linux is the operative system that your server would run. You’re welcome to use any Linux distribution you prefer, such as Ubuntu, RHEL, or CentOS. An operating system is the base software required to make your server function.

Apache

Apache software is in charge of hosting your website. When visitors type your URL in a web browser, your Apache2 service will deliver your website files for viewing.

MySQL

MySQL is a popular database within which to store information for your website. This relational database returns information requested by website visitors and is a common method for storing blog posts, user credentials, or other types of information.

PHP

PHP gives your website a dynamic feel over static pages, a programming language can be used. PHP is a server-side programming language, used by many website designers that gives them the power to create what they want.

What is LAMP?

LAMP is denoting one of the most common solution stacks for many of the web’s most popular applications. however, LAMP now refers to a generic software model and its components are largely interchangeable.
Each letter in LAMP stands for one of its four open-source building blocks
Linux: Operating System/Server
Apache: HTTP Server
MySQL: Relational Database Management System
PHP: Programming Language

Our Task:

  • Install Linux, Apache, MySQL, and PHP (LAMP) stack on AWS.
  • install PHP MYADMIN to access the database.

I have split each task into small steps:

Step 1: Launch Instance(ec2) on Aws.

Step 2: Configure LAMP setup on an instance.

Step 3: Install PHP Myadmin to access the database.

Now, coming to our first step.

Step 1: Launch the Ec2 instance of AWS :

Open the AWS console & go to the Ec2 service of aws

Step 1: Chose AWS AMI for instance

Step 2: Choose Instance Type

Step 3: Configure instance details

Step 4: Add storage

Step 5: Add tags

Step 6: Configure Security Group & allow some port

Step 7: Review the Instance

Now, We can see our instance is launched in the AWS data center in North Virginia (us-east-1)

Our first step is done. Now, move to the second step.

We can remote access our server through the ssh protocol for this we need to connect our ec2 instance through Putty.

Put Public Ip & User Name
Put the Private Key

Now, This way we authenticate our ec2 instance from the local laptop to the data center & access the instance.

Here, we can see our first step is done & now we are authenticated with ec2.

#lscpu: This cmd will tell us about our machine/instance/server

Step 2: Configure LAMP setup on an instance:

#yum install -y httpd : This will launch apache server on aws linux os.
#systemctl start httpd : Start the services of web server.
#systemctl enable httpd : Enable the services of web server when os start autmatic serverice will started, we need to enable it.

#systemctl status httpd : Check status, service in running mode

Now, that we have started the web server, we can copy the public IP and put it into the client-side software i.e, web browser & paste the IP to get the content.

OutPut:

http://15.206.189.152/index.html
Till now our web server is perfectly running.MariaDB is a community developed branch of MySQL#yum install -y mariadb mariadb-server
#yum info mariadb

Now, we want to host some dynamic websites we need PHP & some modules of PHP.

#yum install php php-mysql

If you want to view, what modules we have installed in PHP

#yum search phpNow, we configure the MariaDB server:
#systemctl start mariadb
#systemctl enable mariadb
Now, configure the Mysql server:
#mysql_secure_installation

Till now we have configured all now put content to a web server.

Now, Test Our LAMP Server :

Create a PHP file inside the document root :#cd /var/www/html
#cat > index.php
<?php
phpinfo();
?>
Now, Out from cat using (ctrl+d)
#cat phpinfo.php
: We can see the content
Get the public Ip put into the web browser:
#curl ifconfig.me : Get Your public Ip
http://15.206.189.152/index.php : use this IP

Now, we can access the website using public IP or Public DNS in AWS Cloud.

Step 3: Install PHP Myadmin to access the database.

  • To install phpMyAdmin
1. Install the required dependencies: #yum install php-mbstring -y2. Restart Apache: #systemctl restart httpd3. Restart php-fpm: #systemctl restart php-fpm4. Navigate to default document root: #cd /var/www/html
5. Select a source package for the latest phpMyAdmin release from https://www.phpmyadmin.net/downloads. To download the file directly to your instance, copy the link and paste it into a wget command, as in this example:
#wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
6. Create a phpMyAdmin folder and extract the package :
#mkdir phpMyAdmin && tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1
7. Delete the phpMyAdmin-latest-all-languages.tar.gz tarball file:
#rm phpMyAdmin-latest-all-languages.tar.gz
8. Restart MQSQL server: #systemctl start mariadb

In a web browser, type the URL of your phpMyAdmin installation. This URL is your instance's public DNS address (or the public IP address) followed by a forward slash and the name of your installation directory.

For example :
http://{public ip}/phpMyAdmin

You should see the phpMyAdmin login page:

Till here if you face any issues with the PHP version like this :

Then for solving this issue :Install PHP 7.4, 7.3, 7.2 on Amazon AWS EC2
Let’s confirm that PHP 7.x topic is available in our AWS EC2 machine:
#sudo amazon-linux-extras | grep php
15 php7.2 available \
17 lamp-mariadb10.2-php7.2 available \
31 php7.3 available \
42 php7.4 available &#91; =stable
As we can see all PHP 7 topics, in this example we’ll enable php7.4 topic.#amazon-linux-extras enable php7.4install PHP packages from the repository.#yum clean metadata

#yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
Dependencies Resolved check the php version
#php -v

Thank You..!!

--

--

Niket Ranjan

I’m passionate learner diving into the concepts of computing 💻. I am a Software engineer from India skilled in Linux, DevOps, and Cloud Computing.