ZeroSharp / serverless-php

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:Other


Languages

Language:JavaScript 53.5%Language:Shell 36.6%Language:PHP 9.9%