Most likely, you have heard about and Laravel, the open source PHP framework, and you might be planning to go to the next level to modernize your PHP Laravel application. AWS offers a number of features to help organizations scale to support millions of users, not to mention the agility and cost benefits associated with a cloud infrastructure. These features and capabilities are the compelling promoters to transform your application into a high-performing and resilient PHP Laravel application.
In this article, I will describe how to architect your software-as-a-service (SaaS) Laravel application with high-level scalability standards on AWS to help you understand what is required and discuss the considerations and action items to gain business value and resiliency. We chose the AWS cloud since is the most mature infrastructure-as-a-service (IaaS) provider and makes things easier to innovate; however, these practices can be applied to any cloud platform.
I also will explain why AWS is a vital option to scale and grow your SaaS Laravel application and present the current/future enterprise architecture. In part two of this series, I will discuss the importance of the 12-factor app methodology and multiple lessons to include in your strategy when architecting on AWS DevOps.
The Value of Migrating Your Laravel App to AWS
In an article I wrote for my company blog on running the digital transformation on AWS for your enterprise or web application, I explained the business benefits that brings the AWS cloud adoption, including a reduced IT labor force, pre-configured services to achieve faster implementations and minimal downtime, due to the repeatable and flexible infrastructure. The cloud is an essential environment to scale SaaS Laravel applications—in there, you can decouple your architecture into multiple service pieces, including cloud storage (Amazon S3 and CDN) and automatic scaling EC2 instances (AWS Auto Scaling), and integrate various SaaS/platform-as-a-service (PaaS) AWS components for your modern, cloud-native application. Also, if you are planning to move to the AWS cloud, you could use this AWS Migration Checklist to prepare for your journey.
“Web Applications and enterprises need to transform, they need to transform to a continuous transformation, and the cloud is the key.”
– Stephen Orban
I really enjoyed this phrase from AWS’ Stephen Orban, because you’re not only transforming your application; once on board the AWS cloud, you are in an infinite journey of continuous innovation: pay-as-you-go, microservices, serverless and so on.
Laravel Architecture on Docker and Microservices
Throughout the AWS cloud journey, there have been multiple disruptive evolutions, and one of them is the microservices, although, I won’t cover the microservices (Docker) approach. As a first step to transforming your application toward a cloud-native application, start with a monolithic approach. As your application matures and user base increases, I suggest jumping into a Laravel microservice approach, i.e., dockerize your Laravel PHP product using Docker, AWS ECS, Kubernetes or AWS Fargate. I’ve found many digital agencies that are adopting the AWS Cloud and DevOps practices with Docker/Serverless strategies and are getting overwhelmed with these sophisticated technologies, which has led to project failure because they were not ready to this stage.
Here’s how to avoid that: Grow gradually.
However, if your Dev team has enough experience with Docker and microservices, I wouldn’t hesitate to architect with microservices. This will be covered in the next article in this series, “Microservices with Laravel, Docker and AWS ECS.”
Who is This Article For?
Whether you are kicking off an MVP app on Godaddy/Hostgator, deploying Laravel on AWS with basic principles or ready to jump from hundreds of users into million users, this article is for you and will help you in your Laravel architecture on AWS.
Laravel for Large-Scale SaaS Architecture on AWS
So, let’s start by making clear what do you most need to scale a Laravel application on AWS.
The diagram below illustrates how a next-generation Laravel application should be architected with the full range of AWS DevOps components. Each piece mentioned in this AWS stack is highly elastic, scalable and resilient.
AWS Auto Scaling and Load Balancing
Initially, the dynamic traffic comes from AWS Route53, which will route all requests to the Application Load Balancing, which the AWS ALB will load balance across a fleet of EC2 instances ( 2…N Instances). This fleet should “scale” horizontally according to the traffic demands or the AWS CloudWatch metrics.
Amazon S3 and CloudFront CDN
All static content including images, videos and HTML will be hosted on Amazon S3, the cloud storage with infinite storage and elasticity. In front of Amazon S3, we will compound AWS CloudFront to cache the entire static content and reduce bandwidth costs. Integrating this pair of components is crucial.
AWS RDS Aurora (Managed Database Services)
The database data should be placed on AWS Aurora or RDS and AWS ElastiCache (Redis) for session management and cache user data. These AWS components are elastic and scalable, which helps to design the AWS Well-Architected framework with the highest fault-tolerance and resiliency.
Amazon VPC and Networking
In the AWS Networking level, we propose AWS VPC with a public/private enterprise network. Following PCI and HIPAA practices, there should be a VPN encapsulating the Laravel application within the private AWS enterprise network. Also included should be an AWS VPN connection and OpenVPN service to access the private network to your multiple Laravel environments.
Route53
From the DNS perspective, Route53 is needed to manage the application domain, DNS scalability, routing latency and more features to reduce failures.
AWS Lambda
This serverless component will be used for async jobs and backend scripts to minimize load in your AWS Auto Scaling cluster.
We will explore these AWS components substantially in detail, later in the third article of this series.
Web applications that can fit within this architecture:
- API Laravel applications
- Mobile backend applications
- Laravel enterprise applications: CRMs, ERPs and back-office systems
- SaaS Laravel applications
- Front-end applications. i.e., Angular, React, Vue.js or any HTML site
- ANY web platform: Python, Node.js, Ruby, PHP, Zend, CakePHP, Yii and Symfony
A word of warning: Don’t use Cpanel for any web application. It is not recommended to scale as it can slow down your application performance.