Are you looking to run & deploy your PHP app into AWS Lambda?
Then you’ve come to the right article.
We’ve written a comprehensive guide to deploying PHP applications on AWS Lambda.
As more developers explore the benefits of serverless architecture, it’s essential to understand the available options for running your PHP applications in such environments. AWS Lambda, a popular serverless platform, offers various deployment options to suit your needs.
Deployment Option | Custom Runtime with Serverless Framework | Bref with Serverless Framework | Docker Containers | Laravel Vapor |
---|---|---|---|---|
Difficulty | Moderate to Advanced | Easy to Moderate | Moderate | Easy |
Setup Time | More time-consuming | Quick and straightforward | Moderate | Quick |
Control Over PHP Runtime and Extensions | High | Moderate | High | Low |
Integration with the Serverless Framework | Yes | Yes | Yes | No |
Specific to Laravel Applications | No | No | No | Yes |
Consistency Across Platforms and Environments | No | No | Yes | No |
Community Support and Documentation | Limited | Good | Good | Good |
Subscription Fee | No | No | No | Yes |

Maximize the Value You Get AWS for Your Applications

Stop running in circles and develop your applications faster and cheaper in AWS. This guide will walk you through ways to maximize AWS to generate real value for your needs. We dive into picking the right services to scale, tighten security and maximize costs.
Download our free guide now and get started with confidence.
Article Highlights
- Can PHP be Serverless
- Can you run PHP in AWS Lambda
- Deploying PHP on AWS Lambda using Bref and Serverless Framework
- Deploying PHP on AWS Lambda using Docker
- Easiest: Laravel Vapor managed service
Table of Contents
- Can PHP be Serverless
- Can you run PHP in AWS Lambda
- Deploy PHP on AWS Lambda using Custom Runtime.
- Deploying PHP on AWS Lambda using Bref and Serverless Framework
- Deploying PHP on AWS Lambda using Docker
- Deploying Laravel Applications on AWS Lambda with Laravel Vapor
Can PHP be Serverless
Yes, PHP can be run in a serverless architecture. Serverless computing allows developers to build and run applications without managing any underlying infrastructure. Instead, the cloud provider automatically provisions resources, scales the application based on demand, and charges only for the compute time consumed.
Although PHP is traditionally associated with server-based web applications, it can also be used effectively in serverless environments. With the advent of custom runtimes in platforms like AWS Lambda, it’s now possible to run PHP applications in a serverless architecture.
Serverless PHP applications can benefit from reduced operational overhead, automatic scaling, and cost optimization, as you only pay for your application compute time. This makes PHP a viable option for developers looking to leverage the advantages of serverless computing.
List of Serverless Platforms to Run PHP
- AWS Lambda: AWS Lambda is a popular serverless platform that supports custom runtimes, including PHP. You can deploy PHP applications using custom PHP runtimes, Docker containers, or third-party tools like Bref and Laravel Vapor.
- AWS App Runner: AWS App Runner is a newer service from AWS that allows you to follow a Platform as a Service model like Heroku. You push your PHP application to Github, and App Runner will manage the deployment, autoscaling and infrastructure. You can read our article about it here.
- Google Cloud Functions: While Google Cloud Functions does not have native support for PHP, you can deploy PHP applications using custom runtimes or containers. Utilize Google Cloud Buildpacks for deploying PHP applications in a serverless environment.
- Azure Functions: Azure Functions is Microsoft’s serverless platform that allows running PHP applications using custom handlers and Docker containers. You can deploy your PHP application using the provided Linux-based images or create custom images.
- Vercel: Vercel is a serverless platform known for deploying frontend applications, but it also supports deploying serverless functions using custom runtimes. You can deploy PHP applications on Vercel using the
vercel-php
runtime. - Heroku: While Heroku is a Platform as a Service (PaaS), it provides serverless-like features through Heroku Dynos. You can deploy PHP applications on Heroku using the PHP buildpack or Docker containers.
These serverless platforms allow PHP developers to leverage the benefits of serverless architecture, such as automatic scaling, reduced operational overhead, and cost optimization. Remember that each platform may have specific requirements and limitations when running PHP applications, so reviewing its documentation and guidelines for deploying PHP applications is essential.
Can you run PHP in AWS Lambda
Yes, you can run PHP in AWS Lambda. Although PHP is not officially supported as a native runtime, AWS Lambda allows you to use custom runtimes, making it possible to execute PHP applications in a serverless environment.
There are a few methods to run PHP on AWS Lambda:
- Custom PHP Runtime: You can create a custom PHP runtime using the provided AWS Lambda Runtime API. This involves creating a custom PHP runtime layer and a bootstrap file that handles Lambda events and interacts with the Lambda Runtime API.
- Bref and Serverless Framework: Bref is a popular open-source project that provides a pre-built custom PHP runtime and integrates with the Serverless Framework, simplifying deploying PHP applications on AWS Lambda.
- Docker Containers: AWS Lambda supports custom container images, enabling you to package and deploy PHP applications as Docker containers. You can use the official AWS Lambda base images for PHP or create your custom Docker images.
- Laravel Vapor: Laravel Vapor is a serverless deployment platform designed explicitly for Laravel applications. It integrates seamlessly with AWS Lambda, making it easy to deploy, scale, and manage Laravel applications in a serverless environment.
Using one of these methods, you can deploy and run your PHP applications on AWS Lambda and take advantage of the serverless architecture benefits, such as automatic scaling, reduced operational overhead, and cost optimization based on compute time.
Deploying PHP on AWS Lambda using Custom Runtime and Serverless Framework
A custom PHP runtime allows you to run PHP applications on AWS Lambda using the AWS Lambda Runtime API. Combined with the Serverless Framework, you can streamline the deployment and management of your PHP applications in a serverless environment.
Strengths & Weaknesses
Strengths:
- Full control over the PHP runtime and extensions
- Flexibility to customize the runtime environment as needed
- Integration with the Serverless Framework simplifies deployment and management
Weaknesses:
- More complex and time-consuming setup compared to other solutions
- Requires manual management of PHP runtime updates
- May require more extensive AWS knowledge
Difficulty Rating
Moderate to Advanced
Deployment Steps
- Install the Serverless Framework: Install the Serverless Framework globally on your system using npm:
- Configure AWS credentials: Set up your AWS credentials in the Serverless Framework by following the official guide.
- Create a PHP project: Set up a new PHP project or use an existing one.
- Create a custom PHP runtime layer: Follow the AWS custom runtime documentation to create a custom PHP runtime layer. Package the PHP binary and any required extensions as a Lambda layer.
- Create a bootstrap file: In your PHP project, create a
bootstrap
file that handles Lambda events and communicates with the Lambda Runtime API. - Configure the
serverless.yml
file: In your project directory, create aserverless.yml
configuration file. Configure the custom PHP runtime, Lambda layer, and other settings, such as function handlers and events. - Deploy your PHP application: Deploy your PHP application using the Serverless Framework by running the following command:
Overall Recommendation
Using a custom PHP runtime with the Serverless Framework is suitable for developers who need full control over their runtime environment and extensions. However, it requires more extensive AWS knowledge and time than other solutions like Bref or Laravel Vapor.
When to Use and Avoid This Approach
Use this approach when:
- You need full control over your PHP runtime and extensions
- You require a customized runtime environment for specific needs
- You have experience with AWS Lambda and the Serverless Framework
Avoid this approach when:
- You’re looking for a faster and more straightforward solution
- You’re new to AWS Lambda or the Serverless Framework
- You prefer an out-of-the-box solution like Bref or Laravel Vapor
Deploying PHP on AWS Lambda using Bref and Serverless Framework
Bref is an open-source project that simplifies deploying PHP applications on AWS Lambda. It provides a pre-built custom PHP runtime and integrates with the Serverless Framework, making the deployment process easier and more streamlined.
Strengths & Weaknesses
Strengths:
- Quick and straightforward setup
- Pre-built custom PHP runtime with common extensions
- Seamless integration with the Serverless Framework
- Active community and support
Weaknesses:
- Less control over the PHP runtime compared to creating a custom runtime
- May not cover specific needs or custom extensions
Difficulty Rating
Easy to Moderate
Deployment Steps
- Install the Serverless Framework: Install the Serverless Framework globally on your system using npm:
- Configure AWS credentials: Set up your AWS credentials in the Serverless Framework by following the official guide.
- Install Bref: In your PHP project, install Bref as a dependency using Composer: javascript
- Initialize Bref: Run the following command to create a
serverless.yml
configuration file and a sampleindex.php
file. - Customize the
serverless.yml
file: Edit theserverless.yml
configuration file to define your application’s functions, events, and other settings. - Deploy your PHP application: Deploy your PHP application using the Serverless Framework by running the following command:
Overall Recommendation
Using Bref with the Serverless Framework is an excellent option for developers looking to deploy PHP applications on AWS Lambda quickly and easily. It provides a pre-built custom PHP runtime and simplifies the deployment process, making it suitable for most use cases.
When to Use and Avoid This Approach
Use this approach when:
- You want a quick and straightforward solution
- You don’t require full control over the PHP runtime
- You’re looking for an out-of-the-box solution with community support
Avoid this approach when:
- You need full control over your PHP runtime and extensions
- You have specific needs that Bref may not cover
- You prefer to use Docker containers or other specialized deployment methods
Deploying PHP on AWS Lambda using Docker Containers
Docker containers allow you to package and deploy PHP applications on AWS Lambda using custom container images. This method provides flexibility in configuring the runtime environment and enables you to use the same Docker images across different platforms and stages of your application.
Strengths & Weaknesses
Strengths:
- Consistency across different platforms and environments
- Flexibility in configuring the runtime environment
- Easy integration with your existing Docker-based workflow
- Allows the use of any PHP version and extensions
Weaknesses:
- Requires Docker knowledge and experience
- May have a steeper learning curve for beginners
- May require more time to set up compared to other solutions
Difficulty Rating
Moderate
Deployment Steps
- Install Docker: Ensure that Docker is installed and configured on your system.
- Create a Dockerfile: In your PHP project, create a Dockerfile to define the runtime environment, install the required PHP version and extensions, and configure your application.
- Build the Docker image: Build the Docker image using the
docker build
command, and tag it with an appropriate name. - Push the Docker image to a registry: Push the built Docker image to a container registry, such as Docker Hub or Amazon ECR, using the
docker push
command. - Install the Serverless Framework: Install the Serverless Framework globally on your system using npm.
- Configure AWS credentials: Set up your AWS credentials in the Serverless Framework by following the official guide.
- Create a serverless.yml file: In your project directory, create a
serverless.yml
configuration file. Configure the function to use the Docker image from the container registry. - Deploy your PHP application: Deploy your PHP application using the Serverless Framework by running the
serverless deploy
command.
Overall Recommendation
Using Docker containers to deploy PHP applications on AWS Lambda is an excellent option for developers with Docker experience and require a consistent runtime environment across different platforms. This approach offers flexibility in configuring the PHP runtime but may have a steeper learning curve for beginners.
When to Use and Avoid This Approach
Use this approach when:
- You’re already familiar with Docker and containerization
- You need consistency across different platforms and environments
- You require flexibility in configuring your PHP runtime
Avoid this approach when:
- You’re new to Docker and containerization
- You prefer a more straightforward deployment method
- You want to use a pre-built solution like Bref or Laravel Vapor
Deploying PHP Laravel Applications on AWS Lambda using Laravel Vapor
Laravel Vapor is a serverless deployment platform designed explicitly for Laravel applications. It simplifies deploying, scaling, and managing Laravel applications in a serverless environment on AWS Lambda.
Strengths & Weaknesses
Strengths:
- Tailored for Laravel applications
- Easy setup and deployment process
- Automatic scaling and optimized performance
- Integration with other Laravel ecosystem tools
Weaknesses:
- Limited to Laravel applications
- Paid service with a subscription fee
- Less control over the runtime environment compared to custom solutions
Difficulty Rating
Easy
Deployment Steps
- Install the Vapor CLI: Install the Vapor CLI globally on your system using Composer: javascript
- Create a Vapor account: Sign up for a Laravel Vapor account on the official website.
- Configure AWS credentials: Set up your AWS credentials in Laravel Vapor by following the official documentation.
- Create a new Vapor project: In your Laravel project, run the
vapor init
command to create avapor.yml
configuration file. - Customize the
vapor.yml
file: Edit thevapor.yml
configuration file to define your application’s environment, resources, and other settings. - Deploy your Laravel application: Deploy your Laravel application using the Vapor CLI by running the following command
Overall Recommendation
Laravel Vapor is an excellent option for developers working with Laravel applications looking to leverage serverless architecture on AWS Lambda. It offers a seamless deployment process and integrates well with the Laravel ecosystem. However, it is limited to Laravel applications and requires a subscription fee.
When to Use and Avoid This Approach
Use this approach when:
- You’re working with Laravel applications
- You want an easy and seamless deployment process
- You’re willing to pay for a subscription service
Avoid this approach when:
- You’re not working with Laravel applications
- You need full control over your PHP runtime and extensions
- You prefer a free or open-source solution like Bref or custom runtimes
Run PHP in AWS Lambda
In this article, we’ve explored different approaches to running PHP applications on AWS Lambda. To recap, we’ve covered the following deployment options:
- Custom Runtime with Serverless Framework: This method provides full control over the PHP runtime and extensions but may have a steeper learning curve and requires more time to set up.
- Bref with Serverless Framework: A quick and easy-to-use solution with a pre-built custom PHP runtime, suitable for most use cases but may not cover specific needs or custom extensions.
- Docker Containers: Offers consistency across different platforms and environments, flexibility in configuring the runtime environment, and easy integration with Docker-based workflows.
- Laravel Vapor: A serverless deployment platform tailored for Laravel applications, providing an easy setup and seamless deployment process but limited to Laravel applications and requiring a subscription fee.
Remember that PHP can run in serverless environments, and AWS Lambda is one of the many serverless systems that support PHP. Each deployment option has its strengths and weaknesses, and the best approach for your application depends on your specific needs, experience, and preferences.
In conclusion, running PHP applications on AWS Lambda is a viable option for developers considering serverless architecture. By considering factors such as ease of use, control over the runtime environment, consistency, community support, and cost, you can select the best deployment method for your PHP application in AWS Lambda.
Maximize the Value You Get AWS for Your Applications

Stop running in circles and develop your applications faster and cheaper in AWS. This guide will walk you through ways to maximize AWS to generate real value for your needs. We dive into picking the right services to scale, tighten security and maximize costs.
Download our free guide now and get started with confidence.
Hosting Web Applications in AWS
This article is part of our series to make AWS easy. We love AWS, but let’s be honest. It isn’t effortless. Like way too complicated. We’ve created this learning path to help level you up and get your PHP app onboarded fast.
- Is AWS Cloud Services Hard to Learn?
- AWS PHP Website & Application Hosting Options
- Using PHP in AWS Lambda: Comparing Options
- Deploy Laravel to Elastic Beanstalk using GitHub Actions
- Deploy Laravel from Github to Elastic Beanstalk via CodePipeline
- Install LAMP Stack on AWS EC2
- Install AWS SDK for PHP
- Host and Deploy a Laravel PHP App to AWS Elastic Beanstalk
- Amplify vs Elastic Beanstalk
- AWS App Runner Review
- App Runner vs Elastic Beanstalk
- App Runner vs Fargate
- Elastic Beanstalk vs AWS Lightsail
- Elastic Container Service vs Beanstalk
- Setup & Use AWS Parameter Store in PHP
- How to use AWS Secrets Manager with PHP
- PHP & AWS S3