PHP & lsphp Tuning
OpenLiteSpeed uses lsphp — a PHP build that communicates via LSAPI, which is faster than FastCGI. This page covers every tuning point you will encounter.
How lsphp Works
Browser Request
└── OLS Listener
└── Virtual Host
└── scripthandler: lsapi:lsphp84
└── lsphp process (pool via LSAPI socket)
└── executes .php, returns response
LSAPI is a persistent connection protocol. Workers are kept alive between requests (unlike traditional CGI), which avoids fork overhead.
File Paths — PHP Quick Reference
# PHP binaries by version
/usr/local/lsws/lsphp84/bin/lsphp # PHP 8.4
/usr/local/lsws/lsphp83/bin/lsphp # PHP 8.3
/usr/local/lsws/lsphp82/bin/lsphp # PHP 8.2
/usr/local/lsws/lsphp81/bin/lsphp # PHP 8.1
# php.ini location (for each version)
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini
# Additional ini files (conf.d)
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/conf.d/
# OPcache ini (usually auto-loaded)
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/conf.d/10-opcache.ini
External App Settings (httpd_config.conf)
The extprocessor block controls how OLS manages the lsphp pool.
Tuned extprocessor block
extprocessor lsphp84 {
type lsapi
address uds://tmp/lshttpd/lsphp84.sock
# Path to PHP binary
path /usr/local/lsws/lsphp84/bin/lsphp
# Max simultaneous connections from OLS to this PHP pool
maxConns 35
# PHP children per instance
env PHP_LSAPI_CHILDREN=35
# Fork avoidance: don't fork new processes for responses < this size
env LSAPI_AVOID_FORK=200M
# Keep connection alive after request (persistent)
persistConn 1
# Seconds to wait for first response
initTimeout 60
# Worker instances (1 is fine for most single-server setups)
instances 1
# Memory limits per worker process
memSoftLimit 2047M
memHardLimit 2047M
# Max PHP child processes (hard cap)
procSoftLimit 400
procHardLimit 500
# Queue backlog
backlog 100
# Auto-start workers at server start
autoStart 2
# Priority (nice value, 0 = default)
priority 0
}
Key Tuning Parameters
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
maxConns | 10 | 35 | 100+ |
PHP_LSAPI_CHILDREN | 10 | 35 | 100+ |
procSoftLimit | 100 | 400 | 1000 |
memSoftLimit | 512M | 2047M | 2047M |
For a 2 GB RAM VPS running a WordPress site: maxConns 10, PHP_LSAPI_CHILDREN 10.
php.ini — Critical Settings
/usr/local/lsws/lsphp84/etc/php/8.4/litespeed/php.ini
; ============================================================
; MEMORY
; ============================================================
memory_limit = 256M ; 128M for light sites, 512M for WooCommerce
; ============================================================
; EXECUTION
; ============================================================
max_execution_time = 60 ; seconds — increase for imports/exports
max_input_time = 60
max_input_vars = 5000 ; WordPress may need 5000+
; ============================================================
; UPLOADS
; ============================================================
upload_max_filesize = 64M
post_max_size = 64M
; ============================================================
; OUTPUT
; ============================================================
output_buffering = 4096
; ============================================================
; ERROR HANDLING (production: off; dev: on)
; ============================================================
display_errors = Off
log_errors = On
error_log = /usr/local/lsws/logs/php-error.log
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
; ============================================================
; SESSION
; ============================================================
session.gc_maxlifetime = 1440
session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = Strict
; ============================================================
; DATE
; ============================================================
date.timezone = UTC
OPcache — Must-Enable
OPcache is the biggest single PHP performance improvement. It caches compiled PHP bytecode in memory.
opcache settings in php.ini or conf.d/opcache.ini
; Enable OPcache
opcache.enable = 1
opcache.enable_cli = 0
; Memory for compiled scripts (MB)
opcache.memory_consumption = 128
; String interning memory
opcache.interned_strings_buffer = 16
; Max cached files
opcache.max_accelerated_files = 10000
; Revalidation interval (0 = never check filesystem, fastest)
; Set 0 in production, 2 in development
opcache.revalidate_freq = 0
; Pre-load scripts at startup (PHP 7.4+)
; opcache.preload = /var/www/site/preload.php
; opcache.preload_user = nobody
; JIT (PHP 8.x)
opcache.jit_buffer_size = 64M
opcache.jit = tracing
OPcache Quick Check
# Is OPcache enabled?
/usr/local/lsws/lsphp84/bin/lsphp -r "echo opcache_get_status() ? 'OPcache ON' : 'OPcache OFF';"
# Check from a PHP info page
/usr/local/lsws/lsphp84/bin/lsphp -r "phpinfo();" | grep -i opcache
Per-Vhost php.ini Overrides
You can override php.ini values per virtual host without touching the global ini.
vhconf.conf — phpIniOverride
phpIniOverride {
php_value memory_limit 512M
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 120
php_admin_value open_basedir /var/www/example.com/:/tmp/
}
php_admin_value
php_admin_value sets values that cannot be overridden by scripts or .user.ini. Use for security-sensitive settings like open_basedir.
PHP Extension Management
# Install common extensions (Debian/Ubuntu)
sudo apt install lsphp84-redis # Redis session/cache
sudo apt install lsphp84-imagick # Image processing
sudo apt install lsphp84-mbstring # Multi-byte strings
sudo apt install lsphp84-xml # XML support
sudo apt install lsphp84-curl # cURL
sudo apt install lsphp84-zip # ZIP
sudo apt install lsphp84-intl # Internationalization
sudo apt install lsphp84-gd # GD image library
# Verify extension loaded
/usr/local/lsws/lsphp84/bin/lsphp -m | grep -i redis
/usr/local/lsws/lsphp84/bin/lsphp -m | grep -i opcache
# List all loaded extensions
/usr/local/lsws/lsphp84/bin/lsphp -m
# Check extension path
/usr/local/lsws/lsphp84/bin/lsphp -r "echo ini_get('extension_dir');"
Switching PHP Version for a Vhost
# 1. Install the desired version
sudo apt install lsphp83 lsphp83-common lsphp83-mysql
# 2. Add extprocessor block in httpd_config.conf
sudo vim /usr/local/lsws/conf/httpd_config.conf
# Add lsphp83 block (copy lsphp84 block, change paths)
# 3. Update vhconf.conf scripthandler
sudo vim /usr/local/lsws/conf/vhosts/example/vhconf.conf
# Change: lsapi:lsphp84 → lsapi:lsphp83
# 4. Reload
sudo /usr/local/lsws/bin/lswsctrl restart
# 5. Verify PHP version served (create info.php in web root)
echo "<?php phpinfo();" | sudo tee /var/www/example.com/public/info.php
curl -s http://example.com/info.php | grep "PHP Version"
# Delete after checking!
sudo rm /var/www/example.com/public/info.php
PHP Diagnostics
# Check PHP version
/usr/local/lsws/lsphp84/bin/lsphp -v
# Check all php.ini values
/usr/local/lsws/lsphp84/bin/lsphp -r "phpinfo();" 2>/dev/null | grep -E "memory_limit|upload_max|max_execution"
# Check OPcache status
/usr/local/lsws/lsphp84/bin/lsphp -r "var_dump(opcache_get_status(false));"
# How many lsphp processes right now?
ps aux | grep lsphp | grep -v grep | wc -l
# PHP error log location
/usr/local/lsws/lsphp84/bin/lsphp -r "echo ini_get('error_log');"
sudo tail -20 /usr/local/lsws/logs/php-error.log
Common PHP Problems
| Problem | Cause | Fix |
|---|---|---|
| PHP files download instead of execute | No scripthandler for .php | Add scripthandler { add lsapi:lsphp84 php } |
| 500 error on PHP pages | php.ini error or missing extension | Check /usr/local/lsws/logs/error.log |
| Memory exhausted | memory_limit too low | Increase in php.ini or phpIniOverride |
| Upload fails | upload_max_filesize or post_max_size too small | Increase both in php.ini |
| Session not persisting | Wrong session path/perms | Check session.save_path writable by nobody |
| OPcache not refreshing | revalidate_freq=0 in prod | For dev: set opcache.revalidate_freq=2 |
| Wrong PHP version served | Old extprocessor/scripthandler | Verify vhconf.conf scripthandler and reload |