PHP Environment Variables
LSAPI Environment Variables
Section titled “LSAPI Environment Variables”These environment variables control how lsphp worker processes behave. Set them in the extprocessor configuration in httpd_config.conf:
extprocessor lsphp { type lsapi ... env PHP_LSAPI_CHILDREN=10 env LSAPI_MAX_REQS=5000 env PHP_LSAPI_MAX_IDLE=300 env LSAPI_AVOID_FORK=0 env LSAPI_ACCEPT_NOTIFY=1}Variable Reference
Section titled “Variable Reference”| Variable | Default | Description |
|---|---|---|
PHP_LSAPI_CHILDREN | 10 | Number of PHP worker processes. Each handles one request at a time. |
LSAPI_MAX_REQS | 10000 | Requests a worker serves before exiting and being replaced. Lower values help prevent memory leaks. |
PHP_LSAPI_MAX_IDLE | 300 | Seconds a worker can sit idle before being terminated. |
LSAPI_AVOID_FORK | 0 | Set to 1 to use exec() instead of fork() for new workers. Useful on systems with overcommit disabled. |
LSAPI_ACCEPT_NOTIFY | 1 | Notify parent process when a child accepts a connection. Enables better load balancing. |
LSAPI_PGRP_MAX_IDLE | 300 | Seconds the entire process group can be idle before all workers exit. |
LSAPI_MAX_IDLE_CHILDREN | PHP_LSAPI_CHILDREN / 3 | Maximum number of idle children to keep alive. |
LSAPI_MAX_PROCESS_TIME | 300 | Maximum seconds a single request can take before the worker is killed. |
Sizing PHP_LSAPI_CHILDREN
Section titled “Sizing PHP_LSAPI_CHILDREN”The number of children directly impacts concurrency and memory usage.
Formula:
PHP_LSAPI_CHILDREN = Available_Memory_MB / Per_Worker_MBTypical per-worker memory usage:
| Application | Per-worker memory |
|---|---|
| Static PHP (phpinfo) | 20-30 MB |
| WordPress | 40-60 MB |
| Laravel | 50-80 MB |
| Magento | 80-120 MB |
Example: A server with 4 GB available for PHP running WordPress:
4096 MB / 60 MB = ~68 workers (conservative: 50)Set maxConns in the extprocessor to match PHP_LSAPI_CHILDREN.
php.ini Location
Section titled “php.ini Location”Each lsphp version has its own php.ini:
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.iniIf this file does not exist, lsphp falls back to:
/usr/local/lsws/lsphp84/etc/php.iniTo find the active configuration:
/usr/local/lsws/lsphp84/bin/lsphp -i | grep "Loaded Configuration File"Common php.ini Tuning
Section titled “Common php.ini Tuning”Memory and Upload Limits
Section titled “Memory and Upload Limits”memory_limit = 256Mupload_max_filesize = 64Mpost_max_size = 64Mmax_execution_time = 300max_input_time = 300max_input_vars = 5000OPcache Settings
Section titled “OPcache Settings”OPcache is critical for PHP performance. Enable and tune it:
opcache.enable = 1opcache.memory_consumption = 256opcache.interned_strings_buffer = 16opcache.max_accelerated_files = 10000opcache.revalidate_freq = 60opcache.validate_timestamps = 1opcache.save_comments = 1opcache.fast_shutdown = 1For production servers where code does not change frequently:
opcache.validate_timestamps = 0This disables file modification checks. You must restart lsphp after deploying new code.
Session Configuration
Section titled “Session Configuration”session.save_handler = filessession.save_path = /tmpsession.gc_maxlifetime = 1440For multi-server setups, use Redis or Memcached:
session.save_handler = redissession.save_path = "tcp://127.0.0.1:6379"Error Logging
Section titled “Error Logging”display_errors = Offlog_errors = Onerror_log = /var/log/php/error.logerror_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICTPer-Directory PHP Settings with LiteHTTPD
Section titled “Per-Directory PHP Settings with LiteHTTPD”When the LiteHTTPD module is installed, you can override php.ini values per directory using .htaccess:
php_value memory_limit 512Mphp_value upload_max_filesize 128Mphp_value post_max_size 128Mphp_flag display_errors OffApplying Changes
Section titled “Applying Changes”After modifying environment variables in httpd_config.conf:
systemctl restart lswsAfter modifying php.ini:
# Full restartsystemctl restart lsws
# Or gracefully restart just lsphpkillall -USR1 lsphpMonitoring PHP Workers
Section titled “Monitoring PHP Workers”Check the current number of lsphp processes:
ps aux | grep lsphp | grep -v grep | wc -lMonitor memory usage per worker:
ps -C lsphp -o pid,rss,vsz,pcpu,args --sort=-rssNext Steps
Section titled “Next Steps”- PHP LSAPI — detailed LSAPI architecture
- Install PHP — install additional PHP versions