Complete Guide to LiteSpeed Web Server Virtual Host Template Configuration
This tutorial details how to configure a virtual host template in LiteSpeed Web Server (LSWS) to automatically apply pre-defined optimization settings when creating new virtual hosts. The configuration is based on the latest LSWS version and is suitable for scenarios using the PHP_SuEXEC template.
1. Basic Virtual Host Settings
First, access the LiteSpeed WebAdmin console and navigate as follows:
- Navigation Path: HOME → Configuration → Virtual Host Templates → PHP_SuEXEC → General → Template Settings
- Action: Click the EDIT button and modify these key parameters:
Virtual Host Root: /home/paul/public_html/$VH_NAME/
Config File: $VH_ROOT/config/$VH_NAME.xml
Max Keep-Alive Requests: 1000
Smart Keep-Alive: yes
Document Root: $VH_ROOT/public/
Note: $VH_NAME and $VH_ROOT are built-in LSWS variables representing the virtual host name and root directory path, respectively. They are automatically replaced when a virtual host is created.
2. Log Configuration
Continue configuring log settings within the same template:
- Navigation Path: HOME → Configuration → Virtual Host Templates → PHP_SuEXEC → General → Virtual Host Log
- Modify Parameters:
Use Server's Log: no
File Name: $VH_ROOT/log/error.log
Log Level: ERROR
Rolling Size (bytes): 10M
Note: Storing logs in the virtual host directory simplifies management and troubleshooting. The 10MB rolling size prevents log files from becoming too large.
3. PHP External Application Configuration
This is a crucial step for optimizing PHP performance:
- Navigation Path: HOME → Configuration → Virtual Host Templates → PHP_SuEXEC → External App
- Action: Click on
$VH_NAME_lsphp, then click Edit, and modify these parameters:
Max Connections: 10
Environment: PHP_LSAPI_MAX_REQUESTS=500
Environment: PHP_LSAPI_CHILDREN=20
Back Log: 50
Instances: 10
Run On Start Up: yes
Max Idle Time: -1
Explanation:
Max ConnectionsandInstancescontrol PHP process concurrency; adjust based on server resources.PHP_LSAPI_MAX_REQUESTS=500restarts each PHP child process after 500 requests to prevent memory leaks.PHP_LSAPI_CHILDREN=20sets the number of child processes per instance.Max Idle Time: -1prevents PHP processes from timing out, improving response speed but using more memory.
4. Rewrite Rule Settings
For flexibility, it's recommended to leave rewrite rules in their default state within the template:
- Navigation Path: HOME → Configuration → Virtual Host Templates → PHP_SuEXEC → Rewrite
- Setting: Set Enable Rewrite to Not Set
Note: This allows you to individually enable and configure rewrite rules (e.g., for WordPress permalinks) when creating a specific virtual host, keeping the template generic.
Configuration Summary & Best Practices
After completing the template configuration, every new virtual host created from this template will automatically apply these optimized settings, greatly simplifying bulk site deployment. Keep in mind:
- The number of templates may vary slightly between LSWS versions.
- All variables containing a
$symbol are LSWS predefined variables; do not alter their format. - In production, fine-tune parameters like
Max Connections,Instances, and PHP environment variables based on server CPU, memory, and actual site traffic. - After configuration, always click Graceful Restart at the top of the WebAdmin console for changes to take effect.
By properly configuring a virtual host template, you ensure all new sites have a consistent, optimized foundation, improving management efficiency and site performance.