DEV Community

Cover image for Setting Up A LAMP Stack On AWS
Abisola Adesegun
Abisola Adesegun

Posted on

Setting Up A LAMP Stack On AWS

Table of Contents
Step 1: Launch an EC2 Instance
Step 2: Connect to the EC2 Instance
Step 3: Install Apache
Step 4: Install MySQL
Step 5: Install PHP
Step 6: Set Up Virtual Hosts
Step 7: Test with HTML scripts
Step 8: Enable PHP on the website
Step 9: Configure Apache for PHP

Here’s a step-by-step guide on how to set up a LAMP stack (Linux, Apache, MySQL, PHP) on an AWS EC2 t2.micro instance with Ubuntu 24.04 LTS for a DevOps project.

Step 1: Launch an EC2 Instance

  • Log in to AWS Management Console:

  • Click on Launch Instance.

Image description

  • Configure instance:

Name: Give your instance a name (e.g., "LAMP Server").
AMI: Select Ubuntu 24.04 LTS HVM (64-bit architecture).
Instance type: Choose t2.micro (eligible for free tier).

Image description

Image description

  • Assign a key pair for SSH access.

Image description

  • Configure Security Group:

Add the following rules:
SSH (port 22) for remote access.
HTTP (port 80) for web traffic.
HTTPS (port 443) for secure web traffic.

Image description

  • Launch the instance.

Image description

Image description

Image description

Step 2: Connect to the EC2 Instance

  • Open a terminal (or use VSCode Terminal if preferred).

  • Connect to your instance using SSH:
    Use the key pair to SSH into the instance:

Image description

Image description

  • Update and upgrade the packages:

Image description

Image description

Image description

Step 3: Install Apache

  • Install Apache:

Image description

Image description

  • Verify Apache

Image description

Image description

  • Open your browser and navigate to your EC2 public IP. You should see the Apache default page.

Image description

Or eun the below command:

Image description

Image description

Step 4: Install MySQL

  • Install MySQL Server:

Image description

Image description

Secure MySQL installation:

Image description

Image description

  • Set a root password and follow the prompts to secure your MySQL instance. By following the prompts to set up the root password, remove anonymous users, disallow remote root login, and more.

Image description

Image description

Image description

  • Log in to MySQL to ensure it works: Enter the root password you created, and you should have access to the MySQL shell.

Image description

Image description

Step 5: Install PHP

  • Install PHP and necessary PHP extensions for Apache and MySQL:

Image description

Image description

  • Check PHP Version

Image description

Image description

  • Restart Apache to load PHP:

Image description

Step 6: Set Up Virtual Hosts

  • Create a new directory for your website:

Image description

  • Create a new virtual host file:

Image description

  • Add the following content to configure the virtual host:

Image description

Image description

  • Enable the virtual host using the below commands one by one:

Image description

Image description

Image description

Image description

Step 7: Test with HTML scripts

  • Navigate to the project path

Image description

  • Create an index.html file

Image description

  • Open and edit the file, then paste the html contents below.

Image description

Image description

  • View the contents of index.html file.

Image description

Image description

Image description

Step 8: Enable PHP on the website

Image description

Image description

Image description

Image description

Image description

Step 9: Configure Apache for PHP

  • Update Apache's default directory index file:

Image description

Image description

  • Add the following content:

Image description

  • Save and exit (Ctrl+X, Y, then Enter).

In your browser, go to http:///info.php. You should see a PHP information page.

Image description

  • Thereafter, remove PHP info page: For security reasons, delete the PHP info page after testing:

Image description

  • Access the test file:

Image description

Image description

Top comments (0)