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.
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
serverless.yml file and modify region and stage if necessary.
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.
Compile the static standalone PHP 7 binary
To do this, we have to compile the PHP 7.2.2 with statically linked libraries:
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.