DEV Community

Harsh Viradia
Harsh Viradia

Posted on

Host PHP8.1 Laravel Application using Terraform on AWS.

Architecture Diagram

Image description

In this blog, we will see how to host PHP Laravel application on AWS Elastic Beanstalk. For that kindly follow this blog till end.

Step-1: Create VPC

Create VPC with two public subnets for Elastic Beanstalk and two for RDS instance and Redis cluster. In the public subnet route table allow igw(internet gateway) and for private subnets allow traffic only from local.

Step-2: Host RDS and Redis in the private subnets

Create an RDS instance and Redis cluster in the private subnets.

Note: Kindly select only private subnets in the RDS and Redis subnet groups.

Step-3: Elastic Beanstalk

Create two Elastic Beanstalk, one for students and one for admin.

Key-notes:

  • For EC2 select instance profile and service role.
  • For load-balancer provide health-check path and add 443 listener with SSL certificate.
  • Also add document root /public because it's a PHP application so the document root will be /public directory.
  • Don't forget to enable public IP for instance.
  • Set autoscalling min will 1 and max will 4.

Step-4: CloudFront and Route53

Create Cloudfront for students and give student panel load-balancer DNS name as an origin and allow simple CORS policy. Enable WAF for student and admin panel. Add DNS record in the route53 and access the web application.

Code: https://github.com/harsh-viradia/Host-PHP8.1-Laravel-Application-using-Terraform-on-AWS.
Author: https://www.linkedin.com/in/harsh-viradia/

Top comments (0)