This is an old revision of the document!


Web Cache Web Server Configuration - cPanel/WHM Multi-Site/Shared Hosting

This guide assumes that you have command-line access to the WHM Server. If you do not have command-line access, please refer to cPanel's documentation on editing Apache configuration files through the WHM GUI.

You may set up the Cache Root and Policies in one of three ways:

  • WHM Plugin (Preferred)
  • Command-Line Script
  • Manually from the Command Line

The preferred way to set up the cache root is through the WHM plugin.

Click WHM Plugin > LiteSpeed Configuration > Cache Root Setup

More information on this process can be found on our WHM Plugin page.

Server Level

This screen searches for server-level cache root definitions in either the /usr/local/apache/conf/includes/pre_main_global.conf file or in the LiteSpeed Web Server Web Admin Storage Path setting found under Server > Cache > Cache Storage Settings.

If it is defined in pre_main_global.conf it should look something like this:

<IfModule LiteSpeed>
CacheRoot /home/lscache/
</IfModule>

In this example, the server-level cache root is set to /home/lscache/

VHost Level

Additionally, this screen searches for virtual-host-level cache root definitions in the /usr/local/apache/conf/userdata/lscache_vhosts.conf file.

If it is defined in lscache_vhosts.conf it should look something like this:

<IfModule LiteSpeed>
CacheRoot lscache
</IfModule>

In this example, the vhost-level cache root will be set to /home/<user_folder>/lscache

Set Missing Cache Roots

The Set Missing Cache Roots button sets server-level and vhost-level cache root definitions if they are detected as not set. This button will only appear if at least one of the two cache roots (server level or vhost level) is detected as not set.

You may use the command line instead of the WHM plugin. Simply run the following script, which will set server level and virtual host level cache roots and cache policies:

bash <(curl https://www.litespeedtech.com/packages/lscache/set_cache_root_policy.sh)

Note that this script does not enable cache lookup for users. You can either use the LiteSpeed WordPress Cache Management tools in the LiteSpeed WHM Plugin to manage this in bulk, or add the CacheLookup directive to .htaccess files for individual users manually. This can be done by either the server administrator or the user by adding the following lines:

<IfModule LiteSpeed>
  CacheLookup public on
</IfModule>

For the LiteSpeed Cache for WordPress plugin, both public and private cache are supported. To enable these, you can use:

<IfModule LiteSpeed>
  CacheLookup on
</IfModule>

or

<IfModule LiteSpeed>
  CacheLookup public on
  CacheLookup private on
</IfModule>

The steps that follow will guide you through manually setting cache root and cache policy settings.

Set Server-Level Cache Root

Add the following lines to the /usr/local/apache/conf/includes/pre_main_global.conf file for EA3 or the /etc/apache2/conf.d/includes/pre_main_global.conf file for EA4

<IfModule Litespeed>
CacheRoot /home/lscache/
</IfModule>

Note: It is recommended that you set the server level cache root to /home/lscache/ or a disk partition with enough space.

Set Virtual-Host-Level Cache Root for all Virtual Hosts

Create a lscache_vhosts.conf file in the /usr/local/apache/conf/userdata/ directory for EA3 and the /etc/apache2/conf.d/userdata/ directory for EA4. If these directories do not exist, create them. Your lscache_vhosts.conf file should contain the following lines:

<IfModule Litespeed>
  CacheRoot lscache
</IfModule>

This is done to set each virtual host's cache directory to its home directory (/home/<user>/lscache).

Apply these changes to all virtual hosts by running the following command:

/scripts/ensure_vhost_includes --all-users

Note: You only need to run this command once and it will activate for all users, including new users created by WHM later. There is no need to edit the cPanel skeleton file.

Set Virtual-Host-Level Cache Root for a Single VHost

Example: Apache 2.2 installations with an HTTP site

Create a file named lscache_vhost.conf in the /usr/local/apache/conf/userdata/std/2_2/<user>/<domain>/ directory for EA3 or /etc/apache2/conf.d/userdata/a/std/2_2/<user>/<domain>/ directory for EA4. If this directory does not exist, create it. Add the following lines to the file:

<IfModule Litespeed>
CacheRoot lscache
</IfModule>

This will set the cache directory for this virtual host to /home/<user>/lscache.

Apply these changes to this virtual host by running the ensure_vhost_includes script with the following flag:

/scripts/ensure_vhost_includes --user=$user

For HTTPS sites or Apache 2.4 installations, please refer to cPanel's documentation on modifying virtual host containers with include files.

Note: If different vhosts share the same document root, these vhosts have to share the same vhost-level cache root directory.

Cache Policy Settings

The default LiteSpeed Cache settings work well with most caching scenarios. If you're configuring a shared hosting environment, don't change any of the Server Level default cache policy settings. Leave them as Not Set as below:

Cache Policy:
Enable Public Cache: Not Set
Check Public Cache: Not Set
Max Object Size: Not Set
Cache Expire Time (seconds): Not Set
Cache Stale Age (seconds): Not Set
Cache Request with Query String: Not Set
Cache Request with Cookie: Not Set
Cache Response with Cookie: Not Set
Ignore Request Cache-Control: Not Set
Ignore Response Cache-Control: Not Set
Enable Private Cache: Not Set
Check Private Cache: Not Set
Private Cache Expire Time (seconds): Not Set

Add the following Apache-style configuration directive in your application level document root .htaccess file to enable cache lookup.

<IfModule LiteSpeed>
  CacheLookup public on
</IfModule>

Perform A Graceful Restart

After applying your cache storage settings, perform a graceful restart of LiteSpeed Web Server to have these changes take effect. LiteSpeed Web Server will automatically create cache root directories with proper permissions. Users don't need to manually create any cache root directories themselves.

service lsws restart

Advanced Cache Configuration

For Advanced Cache Configuration info, look here.

  • Admin
  • Last modified: 2018/07/03 15:14
  • by Michael Alegre