Skip to content

Serverless Framework example using an AWS lambda which runs a PHP function

License

Notifications You must be signed in to change notification settings

phpify/serverless-php

 
 

Repository files navigation

PHP with the Serverless Framework

In order to use PHP on AWS Lambda you need to bundle the PHP binary, including the required libraries, into the package. This serverless example project includes the necessary binary to run a simple PHP script.

See my blog post here.

Prerequisites

Install this serverless project. It will create a new serverless-php folder.

serverless install --url https://github.com/ZeroSharp/serverless-php

Deploying the sample function to AWS

Check the serverless.yml file and modify region and stage if necessary.

sls deploy

Running the function locally

sls invoke local --function hello

Running the function on AWS

sls invoke --function hello

Rebuilding the PHP binary

If you need different compiler flags or dependencies you will need to recompile PHP.

Prerequisites

Compile the static standalone PHP 7 binary

To do this, we have to compile the PHP 7.2.2 with statically linked libraries:

sh buildphp.sh

PHP Version

The default is to use the PHP 7.2.2 branch to compile the PHP binary. To switch the PHP version you can set the branch PHP_VERSION_GIT_BRANCH parameter in buildphp.sh line 8.

Thanks

Thanks to:

About

Serverless Framework example using an AWS lambda which runs a PHP function

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 53.5%
  • Shell 36.6%
  • PHP 9.9%