Step-by-Step Guide to Deploying a Laravel App on AWS EC2
Deploying a Laravel application on Amazon Web Services (AWS) gives you a scalable, secure, and high-performance environment for hosting production-grade applications. AWS EC2 provides full control over the server, enabling developers to configure and optimize the stack based on their needs. Whether you are migrating from shared hosting or deploying your first cloud application, this step-by-step guide will walk you through the full deployment process using an EC2 instance.
Prerequisites
Before you begin, ensure the following:
-
A working Laravel application
-
An AWS account
-
Basic understanding of Linux commands
-
Domain name (optional but recommended)
-
Composer and Git knowledge
Step 1: Launch Your EC2 Instance
-
Log into the AWS Management Console
-
Navigate to EC2 Dashboard and click Launch Instance
-
Choose an Amazon Machine Image (AMI)
Recommended: Ubuntu Server 22.04 LTS -
Select Instance Type
Suggested: t3.micro (Free Tier eligible) -
Create a Key Pair to securely access your instance
-
Configure Security Group
Allow inbound:-
SSH (22)
-
HTTP (80)
-
HTTPS (443)
-
-
Launch the instance
Once launched, copy the Public IP address of your instance.
Step 2: Connect to the EC2 Server via SSH
Use the key pair downloaded earlier to connect:
You now have remote access to the EC2 server.
Step 3: Install Required Packages and LAMP Stack
Update packages:
Install Apache:
Install PHP and extensions required by Laravel:
Install Composer:
Install MySQL Client (if needed):
Step 4: Clone Your Laravel Application
Install Git:
Navigate to Apache directory and clone your repo:
Step 5: Set Up Environment Variables
Duplicate the .env file and update it:
Generate application key:
Update .env with database and app details.
Step 6: Install Laravel Dependencies
Run Composer install:
Give storage and bootstrap folder permissions:
Step 7: Configure Apache Virtual Host
Create a new config file:
Add the following:
Enable site and rewrite module:
Step 8: Set Up Database (Optional)
If using Amazon RDS or external DB, configure connection inside .env.
If using local MySQL on EC2, install:
Create DB and user:
Update .env and run migrations:
Step 9: Configure Domain and SSL
Point your domain’s A record to EC2 Public IP.
To secure with HTTPS, install Certbot:
Follow on-screen steps to install SSL certificate.
Step 10: Set Up Supervisor for Queues (Optional but Recommended)
Add:
Enable service:
Conclusion
Deploying a Laravel application on AWS EC2 gives you full control over configuration, scalability, deployment workflows, and performance. By following this guide, you can set up a production-ready environment to run Laravel efficiently, with support for domain routing, SSL, and automated job queues. Once deployed, you can enhance your architecture using RDS, Load Balancers, CloudWatch, and auto-scaling for a highly available cloud environment.