Skip to content
Sample PHP Serverless HTTP application with Bref
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

Sample PHP Serverless HTTP application with Bref

In this sample using AWS Lambda


  • PHP 7.2+
  • AWS account (Must have minimum permission: CloudFormation, CloudWatch, Lambda, S3, API Gateway, and etc.)
  • Node


  1. Get AWS Credential
  2. Install serverless
npm install -g serverless
  1. Config serverless with AWS
serverless config credentials --provider aws --key <key> --secret <secret>
  1. Install bref
composer require bref/bref

Create app

vendor/bin/bref init

will show

What kind of lambda do you want to create? (you will be able to add more functions later by editing `serverless.yml`) [PHP function]:
  [0] PHP function
  [1] HTTP application
  [2] Console application

and type 1

Config app in serverless.yml

function : your function name (in my sample is "reactphp-bref-function")

region : set to your AWS region such as ap-southeast-1

layers : runtime of your app

PHP functions: php-74 and php-73 The simplest way to write a lambda is to write one in the form of a PHP function.

This runtime works great for non-HTTP applications.

HTTP applications: php-74-fpm and php-73-fpm This runtime uses PHP-FPM to run HTTP applications on AWS Lambda.

This runtime is the easiest to start with: it works like traditional PHP hosting and is compatible with Symfony and Laravel.

(

Deployment (Dev)

serverless deploy


Check link to access after deploy (link is generated from API Gateway)

Invocation (On my localhost)

php -S localhost:8000 index.php

Deployment (Production)

If everything working, you can duplicated folder or convert dev function to production by remove dev dependencies, dev config

composer install --prefer-dist --optimize-autoloader --no-dev

and then deploy again

serverless deploy


If you want to delete function

serverless remove
You can’t perform that action at this time.