AI & Web Product Engineer • Last Reviewed: September 2026
This guide walks you through setting up a LAMP stack (Linux, Apache, PHP, MySQL) on an Amazon Linux 2023 EC2 instance. By the end, you'll have a working web server with PHP and a MySQL database.
1. Prerequisites
A running Amazon Linux 2023 EC2 instance.
SSH access to the instance (port 22 open in security group).
Port 80 open in the security group for HTTP traffic.
Connect to your instance:
ssh -i "your-key.pem" ec2-user@your-public-ip
2. Update the System
Always update packages before installing new software:
sudo dnf update -y
Note: Amazon Linux 2023 uses dnf. For Amazon Linux 2, use yum.