How to setup LAMP server on AWS EC2

I’m hoping there would be more people like me who set up LAMP server on AWS Linux EC2 Instance. I’ve done it multiple times and realized that it’s time to write a script to automate the setup.

I’ve shared the script on GitHub. Detailed below are the steps to be followed.

How it works

So I’ve created a script which is supposed to be run in three parts. The reason for three parts is that

  • you need to logout from server to access the changes that have been made by the script. (Maybe there’s a better way and maybe I’ll come across it later).
  • Some people might not want to install phpMyAdmin so they can skip the third script.

The script is broken down in three parts. And each is supposed to be executed one after the other. Don’t forget to logout and login after each part.

Step 0: Clone the repository

Use git clone to clone the repository and set necessary permissions.

git clone
cd aws-lamp

The script needs to be made executable, so run
chmod +x

Step 1: Install php & MySQL

Next step installs php, Mysql and other dependencies.
sudo ./

Once the script has completed running, please exit and login to the server again.

Step 2: Setting Permissions

Next run
sudo ./

Step 3: Installing phpMyAdmin

You may skip this step if you don’t want to install phpMyAdmin

Next install phpMyAdmin with the step 3 script. Here first it is very important to change the IP address field in the script
sudo nano

and modify the below line with your IP address. Replace your-ipaddress with your actual IP address. It would be something like You can check your real ip address from
sudo sed -i -e 's/' /etc/httpd/conf.d/phpMyAdmin.conf

Next run the script
sudo ./

This will install phpMyAdmin and accessible only from the your-ipaddress you defined earlier.

Access phpMyAdmin from any IP

If you would like to allow access to phpMyadmin from any IP Address (although it is insecure, and not recommended), you can do it by editing the phpMyAdmin.conf file located in /etc/httpd/conf.d/.


The above will setup a bare LAMP server on AWS EC2. Comments welcome.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s