- Supported versions
- PHP extensions
- Custom PHP extensions
- Alternate start commands
- PHP Worker sizing hints
- Custom php.ini
- Project templates
PHP is a popular scripting language designed especially for the web. It currently powers over 80% of websites.
Platform.sh also supports HHVM, an alternative PHP engine developed by Facebook that includes several extensions to the PHP language, collectively called "Hack".
Both are interchangeable from a configuration perspective, although code that uses Hack will only run on HHVM.
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
# .platform.app.yaml type: "php:7.0"
You can define the PHP extensions you want to enable or disable:
# .platform.app.yaml runtime: extensions: - http - redis - ssh2 disabled_extensions: - sqlite3
The following extensions are enabled by default:
- json (5.6 and later)
- sockets (7.0 and later)
- mcrypt (5.6 and earlier)
- zendopcache (5.4 only) / opcache (5.5 and later)
You can disable those by adding them to the
This is the complete list of extensions that can be enabled:
note You can check out the output of
ls /etc/php5/mods-availableto see the up-to-date complete list of extensions after you SSH into your environment. For PHP 7, use
It is possible to use an extension not listed here but it takes slightly more work:
Download the .so file for the extension as part of your build hook using
curlor similar. It can also be added to your Git repository if the file is not publicly downloadable, although committing large binary blobs to Git is generally not recommended.
Provide a custom
php.inifile in the application root (as a sibling of your
.platform.app.yamlfile) that loads the extension using an absolute path. For example, if the extension is named
spiffy.soand is in the root of your application, you would have a
php.inifile that reads:
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.
If not specified, the effective default start command varies by PHP version:
- On PHP 5.x, it's
- On PHP 7.0, it's
- On PHP 7.1, it's
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.
Platform.sh uses a heuristic to automatically set the number of workers of a PHP runtime based on the memory available in the container. This heuristic is based on assumptions about the memory necessary on average to process a request. You can tweak those assumptions if your application will typically use considerably more memory. In most cases, however, you should not need to change them unless your application container is swapping a lot.
The heuristic is based on three input parameters:
- The memory available for the container, which depends on the size of the container (
- The memory that an average request is expected to require,
- The memory that should be reserved for things that are not specific to a request (memory for
nginx, the op-code cache, some OS page cache, etc.)
The number of workers is calculated as:
/ ContainerMemory - ReservedMemory \ workers = max|---------------------------------, 2| \ RequestMemory /
The default assumptions are:
45 MBfor the average per-request memory
70 MBfor the reserved memory
You can change them by using the
runtime.sizing_hints.request_memory in your
.platform.app.yaml. For example, if your application consumes on average
110 MB of memory for a request (don't feel bad, we have seen many Drupal websites that do), use:
runtime: sizing_hints: request_memory: 110
To see how much memory your PHP worker processes are using, you can open an SSH session and look at the PHP access log:
In the fifth column, you'll see the peak memory usage that occurred while each request was handled. The peak usage will probably vary between requests, but in order to avoid the severe performance costs that come from swapping, your size hint should be somewhere between the average and worst case memory usages that you observe.
There are two ways to customize
php.ini values for your application. The recommended method is to use the
variables property of
.platform.app.yaml to set ini values using the
php prefix. For example, to increase the PHP memory limit you'd put the following in
variables: php: memory_limit: 256M
It's also possible to provide a custom
php.ini file in the repository in the root of the application (where your
.platform.app.yaml file is).
; php.ini ; Increase PHP memory limit memory_limit = 256M
Another example is to set the timezone of the PHP runtime (though, the timezone settings of containers/services would remain in UTC):
variables: php: "date.timezone": "Europe/Paris"
; php.ini ; Set PHP runtime timezone date.timezone = "Europe/Paris"
php.ini configuration directives can be provided via environment variables separately from the application code. See the note in the Environment variables section.
The default values for some frequently-modified
php.ini settings are listed below.
- This value is on by default to ease setting up a project on Platform.sh. We strongly recommend providing a custom error handler in your application or setting this value to Off before you make your site live.
- Assertions are optimized out of existence and have no impact at runtime. You should have assertions set to `1` for your local development system.
- This is the number of megabytes available for the opcache. Large applications with many files may want to increase this value.
- The opcache will check for updated files on disk. This is necessary to support applications that generate compiled PHP code from user configuration. If you are certain your application does not do so then you can disable this setting for a small performance boost.
We do not limit what you can put in your
php.inifile, but many settings can break your application. This is a facility for advanced users.
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
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.
- EZ Platform
- Drupal 7
- Drupal 7 Commerce Kickstart
- Drupal 8
- Drupal 8 (Multisite variant)
- Magento 1
- Magento 2