Skip to Content
DocumentationPHP runtimes for Lambda

PHP runtimes for AWS Lambda

There is no native support for PHP on AWS Lambda. Instead, we can use third-party runtimes via AWS Lambda custom runtimes.

Bref provides open-source runtimes to run PHP on Lambda. These PHP runtimes are distributed as Lambda runtimes and Docker images.

Bref runtimes

Bref provides 3 PHP runtimes:

  • The “FPM” runtime, to run web applications.
  • The “function” runtime, to run event-driven functions.
  • The “console” runtime, to run CLI commands.

These runtimes are used by the Laravel & Symfony framework integrations to run web applications, console/artisan commands, queues, and more.

The runtimes are available as Lambda runtimes and as Docker images, as explained below.

PHP-FPM runtime for web apps

Name: php-86-fpm, php-85-fpm, php-84-fpm, and php-83-fpm.

This runtime uses PHP-FPM to run web applications on AWS Lambda, like on a traditional server.

It’s the easiest to start with: it works like traditional PHP hosting and is compatible with Symfony, Laravel, and other frameworks.

Learn more about the PHP-FPM runtime.

Event-driven functions

Name: php-86, php-85, php-84, and php-83.

AWS Lambda was initially created to run functions (yes, functions of code) in the cloud.

The Bref “function” runtime lets you create Lambda functions in PHP like with any other language.

This runtime works great to create event-driven microservices.

If you are getting started, we highly recommend using the FPM runtime instead. It’s “PHP as usual” (like on any server), with all the benefits of serverless (simplicity, scaling, etc.).

Learn more about the Function runtime.

Console

Name: php-86-console, php-85-console, php-84-console, and php-83-console.

This runtime lets you run CLI console commands on Lambda.

For example, we can run the Symfony Console  or Laravel Artisan .

Learn more about the Console runtime.

Lambda runtimes or Docker images?

Bref runtimes are distributed in two forms:

  • Lambda runtimes: this is the default. Your code is deployed as a zip archive and runs on Bref’s PHP runtime. This is what runtime: php-84 does in serverless.yml, as explained in the Usage section below and in Runtimes in detail.
  • Docker images: the same runtimes are also published as Docker images (bref/php-84, bref/php-84-dev, etc.). Use them to deploy container images to Lambda instead of zip archives, or to run your application locally.

If you are getting started, use the Lambda runtimes: it is simpler and faster. Docker is useful when your code exceeds the 250MB limit or when you need custom system binaries.

Usage

To use a runtime, set it on each function in serverless.yml:

serverless.yml
service: app provider: name: aws plugins: - ./vendor/bref/bref functions: hello: # ... runtime: php-84 # or: runtime: php-84-fpm # or: runtime: php-84-console

Bref currently provides runtimes for PHP 8.3, 8.4, 8.5, and 8.6:

  • php-86
  • php-85
  • php-84
  • php-83
  • php-86-fpm
  • php-85-fpm
  • php-84-fpm
  • php-83-fpm
  • php-86-console
  • php-85-console
  • php-84-console
  • php-83-console

php-84 means PHP 8.4.*. It is not possible to require a specific “patch” version: functions run on the latest PHP 8.4 version published by Bref (read Runtimes in detail).

The Bref plugin for serverless.yml

Make sure to always include the Bref plugin in your serverless.yml config:

serverless.yml
plugins: - ./vendor/bref/bref

This plugin is what makes runtime: php-84 work (as well as other utilities). It is explained in more detail in the section below.

ARM runtimes

It is possible to run AWS Lambda functions on ARM-based AWS Graviton processors . This is usually considered a way to reduce costs and improve performance.

You can deploy to ARM by using the arm64 architecture:

serverless.yml
functions: api: handler: public/index.php runtime: php-84-fpm architecture: arm64

The same Bref runtimes work on x86 and ARM: there is nothing else to change.

The bref-extra-extensions package is not available for ARM processors yet.

Customer-managed runtimes

PHP is not supported natively on AWS Lambda: Bref publishes its own PHP runtimes as customer-managed Lambda runtimes , one per PHP version.

What the Bref plugin for serverless.yml (the one we include with ./vendor/bref/bref) does is it automatically turns this:

functions: hello: # ... runtime: php-84-fpm

into this:

functions: hello: # ... runtime: arn:aws:lambda:us-east-1:873528684822:runtime/php-84/alias/4 environment: BREF_RUNTIME: Bref\FpmRuntime\Main

☝️ The ARN points to Bref’s runtime for PHP 8.4, in the region of the application. The same runtime runs the FPM, function and console runtimes, on x86 and ARM: the BREF_RUNTIME environment variable tells it which one to start. The 4 alias points to the latest runtime version published for Bref v4.

Last updated on