Rob Allen has a tutorial posted to his site showing how you can run PHP using the serverless lambda functionality that Amazon Web Services provides.
There are other serverless providers, and AWS Lambda is the market leader, but until recently PHP support could most charitably described as cumbersome. That all changed at the end of 2018 with Lambda’s new runtime API and support for layers.
Let’s look at the practicalities of serverless PHP on Lambda with Serverless Framework.
If you'd like to skip to the "good parts" you can check out this repository of the resulting code. Otherwise, he provides a complete walkthrough of the setup and code required to get the lambda up and running:
- compiling the PHP binary on an EC2 instance (so it will be compatible)
- creating a
bootstrapfile for handling requests
- setting up the
ymlconfiguration for the Serverless framework
- writing the "hello world" function
- deploying to the lambda system
Finally he shows how to call the "hello" function using the command line and the response you should receive.