PHP Support

PHP is a popular scripting language designed especially for the web. It currently powers over 80% of websites.

Supported versions

  • 5.6
  • 7.0
  • 7.1
  • 7.2

Note that as of PHP 7.1 we use the Zend Thread Safe (ZTS) version of PHP.

To select a PHP version, specify a type such as php:7.2:

# .platform.app.yaml
type: "php:7.2"

Deprecated versions

The following versions are available but are not receiving security updates from upstream, so their use is not recommended. They will be removed at some point in the future.

PHP

  • 5.4
  • 5.5

Alternate start commands

PHP is most commonly run in a CGI mode, using PHP-FPM. That is the default on Platform.sh. However, you can also start alternative processes if desired, such as if you're running an Async PHP daemon, a thread-based worker process, etc. To do so, simply specify an alternative start command in platform.app.yaml, similar to the following:

web:
    commands:
        start: php run.php
    upstream:
            socket_family: tcp
            protocol: http

The above configuration will execute the run.php script in the application root when the container starts using the PHP-CLI SAPI, just before the deploy hook runs, but will not launch PHP-FPM. It will also tell the front-controller (Nginx) to connect to your application via a TCP socket, which will be specified in the PORT environment variable. Note that the start command must run in the foreground.

If not specified, the effective default start command varies by PHP version:

  • On PHP 5.x, it's /usr/sbin/php5-fpm.
  • On PHP 7.0, it's /usr/sbin/php-fpm7.0.
  • On PHP 7.1, it's /usr/sbin/php-fpm7.1-zts.
  • On PHP 7.2, it's /usr/sbin/php-fpm7.2-zts.

While you can call it manually that is generally not necessary. Note that PHP-FPM cannot run simultaneously along with another persistent process (such as ReactPHP or Amp). If you need both they will have to run in separate containers.

Debug PHP-FPM

If you want to inspect what's going on with PHP-FPM, you can install this small CLI:

dependencies:
  php:
    wizaplace/php-fpm-status-cli: "^1.0"

Then when you are connected to your project over SSH you can run:

$ php-fpm-status --socket=unix:///run/app.sock --path=/-/status --full

Project templates

A number of project templates for major PHP applications are available on GitHub. Not all of them are proactively maintained but all can be used as a starting point or reference for building your own website or web application.

Applications

Frameworks