Source: Introducing PHP 7.2 runtime on the App Engine standard environment from Google Cloud
Today, Google Cloud is announcing the availability of PHP 7.2 on the App Engine standard environment, our latest Second Generation runtime. It is available today in beta, so you can build and deploy reliable applications with even more flexibility. Similar to the other Second Generation runtimes on App Engine standard (Python 3.7 and Node.js 8), PHP 7.2 is open and idiomatic, so you can run popular frameworks like Symfony, Laravel, and even WordPress.
You can see more on using PHP 7.2 on App Engine standard here:
PHP 7.2 apps get all the benefits of App Engine standard: auto-scaling instances in seconds, allowing your app to handle sudden bursts in demand; faster deployment times—usually in under a minute for PHP apps; and scaling down to zero instances if needed, making it perfect for apps that operate at any scale. Since PHP 7.2 is a Second Generation runtime, you can run any code without restrictions. Existing PHP apps and open source libraries will run unmodified.
If you’re a long-time App Engine fan, you may have noticed that we are shipping new runtimes faster than we have in the past. This is due to the introduction of Second Generation runtimes, which are based on gVisor technology. Since we don’t need to custom-modify language runtimes to work with App Engine, support for new languages can be launched quickly.
To help you get started with PHP on App Engine, we’ve built a collection of getting started guides and samples to walk you through creating your code, using our APIs and services, and deploying to production. Additionally, you can check out these tutorials for deploying WordPress, Laravel, Symfony, and Slim Framework applications.
To deploy a simple application to App Engine on PHP 7.2, download and install the Google Cloud SDK. Once you’ve done this, create
index.php files as shown below:
And finally, deploy to App Engine:
PHP 7.2 and the other new runtimes are opinionated on using a front controller. This means all traffic goes through a single PHP file. Most modern PHP frameworks use a front controller, including Laravel, Symfony, and Drupal. By default, App Engine serves all traffic to either
index.php, but this can be changed by updating the
entrypoint directive in
The serve command handles running the App Engine web server. Read more about it in the app.yaml reference documentation.
If you are new to the world of front controllers, use a microframework such as the Slim Framework to get started. It provides a very straightforward way to define routes in your application, as shown here:
For applications that do not map well to a front controller (e.g. a flat-file PHP application), consider doing something similar to this WordPress front controller, where a wrapper controller routes requests to the other files in the application.
The new PHP 7.2 runtime supports Google Cloud client libraries, so you can integrate Google Cloud services into your app and run it on App Engine, Compute Engine, or any other platform. At Google Cloud Next we also announced Cloud Scheduler and Cloud Tasks—services that mirror App Engine's popular scheduling and queueing functionality (App Engine cron and Task Queues). We are progressively evolving all of these original App Engine APIs to make them accessible from anywhere. However, at this time, the original App Engine-only APIs are not available for Second Generation runtimes, including PHP 7.2.
To use Google Cloud client libraries, install them using Composer, like this:
You can write apps using PHP 7.2 today on the App Engine standard environment—check out the docs to get started. And since it's a Second Generation runtime, you can expect much faster updates, so stay tuned!