Configure PHP on TurboStack

Select a PHP version per application on TurboStack and tune PHP-FPM, OPcache and ionCube through the supported YAML keys.

Each application chooses its own PHP version and, optionally, its PHP-FPM and OPcache tuning.

The PHP panel under Configure application > Technologies, enabled, with the Select PHP Version field and Advanced Settings expanded to show the PHP-FPM worker fields, the tmp dir option and Enhance Opcache
The PHP panel under Configure application > Technologies, enabled, with the Select PHP Version field and Advanced Settings expanded to show the PHP-FPM worker fields, the tmp dir option and Enhance Opcache

Where to configure it

PHP is configured per application:

  1. Open the application.
  2. Go to Configure application > Technologies > PHP.
  3. Select the PHP version (and adjust advanced settings if needed).

The host installs every version its applications select. The host-level php_main_version sets the default for the command line.

YAML configuration

Required

Key Meaning
php_version PHP version for this application/vhost, e.g. "8.4".

Optional

A PHP-FPM worker is one PHP process that handles one request at a time, so the number of workers sets how many PHP requests the application can serve at once.

Key Meaning
php_fpm_pm_start_servers Number of PHP-FPM worker processes started initially.
php_fpm_pm_min_spare_servers Minimum number of idle PHP-FPM workers kept ready.
php_fpm_pm_max_spare_servers Maximum number of idle PHP-FPM workers kept ready.
php_fpm_pm_max_children The ceiling on workers this application may run at once. Inherited from the host unless you set it here.
php_fpm_pm_max_requests How many requests a worker handles before it is restarted. Inherited from the host (500) unless you set it here.
php_user_tmp_dir Gives the application its own temporary folder instead of the shared one. Off by default.
php_enhance Enable OPcache performance enhancements for the site.
php_opcache_preload_script Path to a script preloaded into OPcache at startup.
php_ioncube_enabled Enable the ionCube loader (for ionCube-encoded apps).
php_main_version Host-level: default PHP version for the host (the php command on the command line).
php_opcache_memory_consumption Host-level: the OPcache memory segment, in MB. Default 512. Applies to every PHP version on the host.
php_opcache_interned_strings_buffer Host-level: the part of that segment reserved for interned strings, in MB. Default 32. It must stay smaller than php_opcache_memory_consumption.
php_opcache_max_accelerated_files Host-level: how many PHP files the OPcache can hold. Default 30000.
# Per-application
php_version: "8.4"

# Optional PHP-FPM tuning
php_fpm_pm_start_servers: 5
php_fpm_pm_min_spare_servers: 3
php_fpm_pm_max_spare_servers: 6
# php_fpm_pm_max_children: 40      # ceiling on concurrent workers
# php_fpm_pm_max_requests: 500     # restart a worker after this many requests
# php_user_tmp_dir: true           # a private tmp folder for this application

# Optional OPcache + ionCube
php_enhance: true
php_opcache_preload_script: "/var/www/prod/preload.php"
php_ioncube_enabled: false

# Host-level
php_main_version: "8.4"
# php_opcache_memory_consumption: 512        # MB, every PHP version on the host
# php_opcache_interned_strings_buffer: 32    # MB, must be smaller than the line above
# php_opcache_max_accelerated_files: 30000

Worker ceiling and recycling

php_fpm_pm_max_children is the hard limit on how many requests this application can process at the same time. Every worker holds its own memory, so the ceiling multiplied by the memory a request uses is the worst case for this application. Set it too high and a traffic peak pushes the host out of memory; set it too low and requests queue and time out. See Out of memory and Performance tuning.

php_fpm_pm_max_requests restarts a worker after that many requests. Restarting reclaims whatever the process leaked, which keeps a slowly growing application stable without a scheduled restart.

Both are inherited from the host when you leave them out, so set them per application only when one site needs to differ from the rest.

Publishing checks the worker settings before applying changes. The minimum idle worker count must be at least 1. The remaining values must satisfy:

php_fpm_pm_min_spare_servers <= php_fpm_pm_start_servers <= php_fpm_pm_max_spare_servers <= php_fpm_pm_max_children

If publishing reports inconsistent worker settings, adjust the values for the application named in the error and publish again. Include inherited host values when checking this order.

A private temporary folder

With php_user_tmp_dir: true the application gets its own tmp folder under its home directory, owned by its own user, and PHP's sys_temp_dir points at it. Without it, applications share the system temporary folder. Turn it on when several applications run on one host and you do not want uploads, sessions or generated files landing in a place another application can read.

OPcache sizing

The three php_opcache_* keys size the OPcache for the whole host, for every installed PHP version. The Health tab monitors the three values they control: memory usage, interned strings usage and the number of cached files. Raise a key when the matching check warns. Keep php_opcache_interned_strings_buffer below php_opcache_memory_consumption. A publish with an equal or larger value is refused, because PHP-FPM would not start.

Set the two memory values as plain integers in megabytes (MB), without a suffix. Set php_opcache_max_accelerated_files as a file count. Each PHP version has its own memory segment, so check available host memory before increasing it. See the host-wide OPcache reference for defaults and the host-level configuration example.

These keys are set in the Source (YAML) view, not in the GUI. Some hosts had opcache.memory_consumption, opcache.interned_strings_buffer or opcache.max_accelerated_files in a custom PHP configuration file. Such a host keeps the largest value it had. The platform moved that value into the host configuration and removed the line from the file.

OPcache preloading

Normally PHP loads the parts of your framework it needs on every request. Preloading loads them once, when PHP starts, and keeps them in memory for every request after that. For a framework that supports it, such as Symfony or Laravel, that is a noticeable speed gain.

Point php_opcache_preload_script at the script your framework provides:

php_opcache_preload_script: "/var/www/prod/preload.php"

Three rules decide whether it works at all:

  • One application per PHP version. PHP loads exactly one preload script per PHP version, for the whole server. If two applications on the same PHP version both set the key, the deployment stops with an error. Give one of them a different php_version, or set the key on only one.

  • The file must exist when you publish, or the deployment fails.

  • Preloading is available on the platform's standard Linux hosts, not on control-panel hosts.

Applying a change

This is the part that surprises people, so it is worth being precise. Two different things can change, and they need different actions.

What changed What to do
The setting php_opcache_preload_script Nothing extra. Publish the host and TurboStack applies it.
The contents of the preload script Reload PHP yourself: sudo systemctl reload php<version>-fpm.service

Publishing does not help in the second case, because nothing in your host configuration changed - only a file on disk. And preloaded code is deliberately held outside the normal OPcache, so clearing that cache does not refresh it either.

# You edited /var/www/prod/preload.php. Apply it:
sudo systemctl reload php8.4-fpm.service

The reload takes about a tenth of a second and serves visitors throughout. It applies to every application on that PHP version - see Administrator access.

What does not work

This does not apply a preload change Why
tscli opcache clear It clears the ordinary OPcache. Preloaded code is kept separately and survives it.
Reloading or restarting Nginx Nginx passes requests to PHP. It holds no PHP code.
Publishing the host again Your configuration did not change, so nothing is applied.
tscli php kill It does work, but it stops all PHP on the host for roughly 15 to 20 seconds. The reload above does the same thing with no downtime.

Common tasks