Introducing the PHP Functions Framework. This open source library allows you to easily deploy PHP applications to Cloud Run. In this blogpost, we’ll give you a quick introduction to this package and show you how to deploy a PHP function to Cloud Run!💨👟
PHP Functions Framework
The PHP Functions Framework allow anyone to easily develop self-contained PHP functions with a FaaS developer experience that can be run/tested locally and deployed to the Cloud. The framework is a package published on Packagist and source code is on GitHub.
Develop PHP Functions
The PHP Functions Framework allows you to use Symfony’s object-oriented web application framework to create simple HTTP request handlers. While testing on your computer, you can use PHP’s built-in web server (via a simple CLI command) to run your function’s code that responds to HTTP requests.
The framework is best illustrated with a sample. Let’s create a “Hello World” example by writing a simple function in a new file,
Then specify this dependency on the framework in a
Install this package with
Finally, run the Functions Framework locally with the following script that uses PHP’s built-in web server:
php -S localhost:8080 vendor/bin/router.php
exportcommands only need to be run once initially.
http://localhost:8080/, you’ll see your PHP server running locally! 🐘
Containerize your Application
The PHP Function Framework is portable, meaning you can take your existing application code with the Functions Framework and run it anywhere that supports PHP.
The PHP Functions Framework repo includes an example
Dockerfile that we can use/copy to build our container. Add the contents of this file (copied below) to a new file named
Dockerfile next to your
Deploy to Cloud Run
Deploying your application to Google Cloud is easy. Run the following commands to build your container and deploy to Cloud Run 💨👟:
# Set env var "GCP_PROJECT" to our project name
GCP_PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)# Set our Cloud Run region (so we aren't prompted)
gcloud config set run/region us-central1# Build and upload your image in Google Container Registry
gcloud builds submit --tag gcr.io/$GCP_PROJECT/hellophp
gcloud run deploy hellophp \
--image gcr.io/$GCP_PROJECT/hellophp \
--region us-central1 \
After ~30 seconds, you’ll get a URL that looks like this:
Feel free to
curl your URL as much as you want and invoke our function!
There you have it! You’ve deployed your first PHP function to Google Cloud!
Eager to learn more about Function Frameworks with Google Cloud?