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, collectivelly 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
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 AmPHP). 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 or less memory. In most cases, however, you should not need to change them.
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.
You can also create and push a
php.ini file that will be appended to
the configuration maintained by Platform.sh.
In your repository, the
php.ini file should be added to the root of
the application (normally the repository root).
For example, if you need to increase the PHP memory limit:
; 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):
; php.ini ; Set PHP runtime timezone date.timezone = "Europe/Paris"
After pushing your file, you can check that the custom PHP configuration has been added to your environment by logging in via SSH and type:
web@kjh43kbobssae-master--php:~$ cat /etc/php5/fpm/php.ini ; =============== Custom configuration from `/app/php.ini` ; Increase PHP memory limit memory_limit = 256M ; Set PHP runtime timezone date.timezone = "Europe/Paris"
php.ini configuration directives can be provided via environment variables. See the note in the Environment variables section.
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.