This guide explains how to set up a LAMP stack on AWS EC2.
We actively run websites on AWS EC2, and based on our hands-on experience, this guide walks you through how to set up a LAMP stack on an EC2 instance.
For a clear overview of the LAMP stack, refer to the following official AWS article:
https://aws.amazon.com/what-is/lamp-stack
Prerequisites
Before proceeding with this guide, make sure you have created an AWS account by completing the steps below.
- You have already created an AWS account by following the official AWS guide below:
https://aws.amazon.com/resources/create-account/
Access the AWS Management Console
First, access the AWS Management Console.
Go to the URL below and click “Sign In to the Console.”

The AWS Management Console is a web-based interface that allows you to manage AWS services through a graphical user interface (GUI).
Accessing the Management Console simply means logging in to your AWS account.


Open the EC2 Console
Go to the EC2 Dashboard in the AWS Management Console.

Choose the region where you will launch your EC2 instance
Set the region displayed in the top-right corner of the AWS Management Console to the region where you want to launch your EC2 instance.
In this example, we will launch the EC2 instance in United States (N. Virginia).

Launch an instance
Click the yellow “Launch instance” button to navigate to the screen where you can enter the required information to create your EC2 instance.

On the following screen, enter the required information to launch your EC2 instance.

In this example, we will launch the EC2 instance using Amazon Linux 2023.
Amazon Linux 2023 is a Fedora-like Linux distribution that is optimized for performance, security, and integration within AWS environments.
Name and tags
Set a name for your EC2 instance. This name is used to help you identify the instance.
Instance type
Instance types define the compute resources of a server, such as CPU and memory, and directly impact its performance. When you select Amazon Linux 2023, the default instance type is set to t3.micro.
For running WordPress, t3.micro provides the minimum level of performance. While it can run WordPress, it is recommended to choose an instance type of t3.small or higher if you plan to use resource-intensive plugins or frequently update your site with new content.
Network Setting
Setup EBS Volume
Connect EC2 Instance with SSH Protocol
ED25519 key fingerprint is: SHA256: *******************
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
, #_
~\_ ####_ Amazon Linux 2023
~~ \_#####\
~~ \###|
~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023
~~ V~' '->
~~~ /
~~._. _/
_/ _/
_/m/'
Build a LAMP stack on Amazon Linux 2023
Based on the following official AWS documentation, we will set up a LAMP stack on the Amazon Linux 2023 instance we launched.
First, run the following command:
sudo dnf upgrade -y
This command updates all installed packages to the latest versions, ensuring that the system has the latest security patches and bug fixes.
Packages to Install
Install the following packages:
- NGINX or Apache
- MariaDB or MySQL
- PHP
By installing these components, you will set up a LAMP stack on your Linux environment.
Overview and Installation of wget
Install and Configure NGINX or Apache
First, run the following command to install NGINX on Amazon Linux 2023:
$ sudo dnf install nginx -y
Install and Configure MariaDB or MySQL
$ sudo dnf install mariadb
Install and Configure PHP and Its Extensions
$ sudo dnf install php php-fpm php-json php-zip php-gd php-mysqli php-mysqlnd php-mbstring php-xml


