Documentation
Other frameworks
Getting Started

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/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:

vendor/bin/bref init

Accept all the defaults by pressing "Enter". The following files will be created in your project:

  • index.php contains the code of your application
  • serverless.yml contains the configuration for deploying on AWS

You are free to edit index.php.

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:

serverless.yml
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

Deployment

To deploy, run:

serverless deploy

Once the command finishes, it should print a URL like this one:

https://3pjp2yiw97.execute-api.us-east-1.amazonaws.com

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.

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.