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:
Setup
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/brefMake sure that the version of Bref that was installed is 3.0 or greater.
Then, create a serverless.yml file. This file will describe how to deploy your application.
service: app # your application name (lowercase without spaces)
bref:
# Uncomment and set your team ID if you are using Bref Cloud
#team: bref-team-id
provider:
name: aws
region: us-east-1 # AWS region to deploy to
environment: # Environment variables
APP_ENV: prod
functions:
web:
# `index.php` is the entrypoint of your application
handler: index.php
runtime: php-84-fpm
timeout: 28 # in seconds (API Gateway has a max timeout of 29 seconds)
events:
- httpApi: '*'
package:
patterns: # Exclude files from deployment
- '!node_modules/**'
- '!tests/**'
plugins:
- ./vendor/bref/brefIf your index.php entrypoint is in a different folder, feel free to adjust the handler key. For example if it is in public/index.php:
handler: public/index.phpIf this is a new application, you can create a very simple index.php file to test things out, for example:
<?php
echo 'Hello world!';You will also want to add .serverless to your .gitignore.
Deployment
To deploy, run:
serverless deployOnce the command finishes, it should print a URL like this one:
https://3pjp2yiw97.execute-api.us-east-1.amazonaws.comOpen 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.
Troubleshooting
In case your application is showing a blank page after being deployed, have a look at the logs.
Website assets
Have a look at the Website guide to learn how to deploy a website with assets.