Getting started - Bref with any framework
This guide will help you deploy your first PHP application on AWS Lambda. The instructions below can be adapted to work with any framework.
If you are using Laravel or Symfony, check out the dedicated guides instead:
First, follow the Setup guide to create an AWS account and install the necessary tools.
Next, in an empty directory, install Bref using Composer:
composer require bref/bref
Make sure that the version of Bref that was installed is 1.0 or greater.
Then let's start by initializing a new project by running:
Accept all the defaults by pressing "Enter". The following files will be created in your project:
index.phpcontains the code of your application
serverless.ymlcontains the configuration for deploying on AWS
You are free to edit
To deploy an existing application, you can delete
index.php and edit
serverless.yml to point to your existing index file (for example it may be another file like
public/index.php). You can also create the
serverless.yml file manually:
service: app provider: name: aws region: us-east-1 functions: web: handler: index.php runtime: php-81-fpm events: - httpApi: '*' package: patterns: # Exclude files from deployment - '!node_modules/**' - '!tests/**' plugins: - ./vendor/bref/bref
To deploy, run:
Once the command finishes, it should print a URL like this one:
Open this URL and you should see your application:
index.php is running on Lambda!
Congrats on creating your first serverless application 🎉
To learn more about deployments, head over the Deployment guide.
In case your application is showing a blank page after being deployed, have a look at the logs.
Have a look at the Website guide to learn how to deploy a website with assets.