Configure PHP on TurboStack
Each application chooses its own PHP version and, optionally, its PHP-FPM and OPcache tuning.
Where to configure it
PHP is configured per application:
- Open the application.
- Go to Configure application > Technologies > PHP.
- 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
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.
# 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
Note
Each application runs in its own PHP-FPM pool, so php_version and the PHP-FPM tuning
keys apply independently per site. The host installs every PHP version its applications
select. A version that no application uses any more is removed on the next publish.
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.
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
Tip
To check that preloading is actually active, have your application run
print_r(opcache_get_status()['preload_statistics']);. If the key is missing, PHP is not
preloading anything.
Common tasks
Related
- What is PHP?
- Applications: Technologies
- Applications overview
- TurboStack CLI - clear OPcache (
tscli opcache clear) and manage Blackfire