Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
litespeed_wiki:cache:common_installation:cpanel-shared [2017/10/26 18:56]
Jackson Zhang [Web Cache Web Server Configuration - cPanel/WHM Multi-Site/Shared Hosting]
litespeed_wiki:cache:common_installation:cpanel-shared [2019/01/25 19:37]
Lisa Clarke [Setting Cache root to a secondary disk (with CageFS)] Proofreading
Line 3: Line 3:
 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 [[https://​documentation.cpanel.net/​display/​EA/​Advanced+Apache+Configuration#​AdvancedApacheConfiguration-ModifyyourglobalApacheconfiguration|editing Apache configuration files]] through the WHM GUI. 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 [[https://​documentation.cpanel.net/​display/​EA/​Advanced+Apache+Configuration#​AdvancedApacheConfiguration-ModifyyourglobalApacheconfiguration|editing Apache configuration files]] through the WHM GUI.
  
-Simply run the following script, which will set server level and virtual host level cache roots and cache policies:+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 
 + 
 +===== Setting Cache Root via WHM Plugin ===== 
 +The preferred way to set up the cache root is through the WHM plugin. 
 + 
 +Click **WHM Plugin > LiteSpeed Configuration > Cache Root Setup** 
 + 
 +{{:​litespeed_wiki:​cpanel:​screen_shot_2016-09-29_at_10.45.06_am.png?​nolink|}} 
 + 
 +More information on this process can be found on our [[litespeed_wiki:​cpanel:​whm-plugin-lscwp-management#​cache_root_setup|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. 
 + 
 +===== Setting Cache Root and Policies from a Command Line Script ===== 
 +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)   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 (the management tools will add the ''​CacheLookup''​ directive to the related .htaccess files), or add the ''​CacheLookup''​ directive to ''​.htaccess''​ files for individual users manually. This can be done by either the server administrator or the user themselves ​by adding the following lines:+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>​   <​IfModule LiteSpeed>​
     CacheLookup public on     CacheLookup public on
   </​IfModule>​   </​IfModule>​
  
-For litespeed wordpress cache plugin, ​it supports ​both public and private cache. To enable ​both public and private lookup, you can use: +For the LiteSpeed Cache for WordPress ​plugin, both public and private cache are supported. To enable ​these, you can use: 
   <​IfModule LiteSpeed>​   <​IfModule LiteSpeed>​
     CacheLookup on     CacheLookup on
Line 24: Line 65:
   </​IfModule>​   </​IfModule>​
  
-//​**Note:​** ​The steps that follow will guide you through manually setting cache root and cache policy settings. ​If the above script has already been run, there is no need to follow these steps.// +===== Setting Cache Root and Policies Manually from the Command Line ===== 
-===== Cache Storage Settings ===== +The steps that follow will guide you through manually setting cache root and cache policy settings. 
-==== Set Server ​level cache root ====+ 
 +==== 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 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
  
Line 35: Line 77:
 **Note:** It is recommended that you set the server level cache root to ''/​home/​lscache/''​ or a disk partition with enough space. **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 ====  +==== 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:+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:
  
 <​code>​ <​code>​
Line 44: Line 86:
 </​code>​ </​code>​
  
-This is done to set each Virtual Hosts' cache directory to its home directory (''/​home/<​user>/​lscache''​).+This is done to set each virtual host'cache directory to its home directory (''/​home/<​user>/​lscache''​).
  
-Apply these changes to all Virtual Hosts by running the following command: ​+Apply these changes to all virtual hosts by running the following command: ​
  
 <​code>​ <​code>​
Line 52: Line 94:
 </​code>​ </​code>​
  
 +**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 ====
  
-//**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 **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) with the following lines:+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:
  
 <​code>​ <​code>​
Line 67: Line 108:
 </​code>​ </​code>​
  
-This will set the cache directory for this Virtual Host to /​home/<​user>/​lscache.+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:+Apply these changes to this virtual host by running the ''​ensure_vhost_includes''​ script with the following flag:
  
 <​code>​ <​code>​
Line 77: Line 118:
 For HTTPS sites or Apache 2.4 installations,​ please refer to cPanel'​s documentation on [[https://​documentation.cpanel.net/​display/​EA/​Modify+Virtualhost+Containers+With+Include+Files|modifying virtual host containers with include files]]. For HTTPS sites or Apache 2.4 installations,​ please refer to cPanel'​s documentation on [[https://​documentation.cpanel.net/​display/​EA/​Modify+Virtualhost+Containers+With+Include+Files|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.//+**Note:** If different vhosts share the same document root, these vhosts have to share the same vhost-level cache root directory.
  
-===== Cache Policy Settings ​===== +==== 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: 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:   Cache Policy:
   Enable Public Cache: Not Set   Enable Public Cache: Not Set
Line 105: Line 147:
 </​code>​ </​code>​
  
-//**Note:** If you are enabling LiteSpeed Cache through our [[litespeed_wiki:​cpanel:​whm-plugin-lscwp-management|WHM Plugin]], you may skip enabling cache lookup manually as the LiteSpeed Cache Management tool will add CacheLookup to .htaccess files for you.// +==== Perform A Graceful Restart ====
- +
-===== 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. 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.
  
Line 114: Line 154:
 </​code>​ </​code>​
  
-===== Advanced Cache Configuration ​=====+==== Advanced Cache Configuration ====
 For Advanced Cache Configuration info, **[[litespeed_wiki:​cache:​common_installation:​advanced|look here]]**. For Advanced Cache Configuration info, **[[litespeed_wiki:​cache:​common_installation:​advanced|look here]]**.
 +
 +===== Setting Cache Root to a Secondary Disk (with CageFS) =====
 +In some environments,​ you might run with normal hard drives for ''/​home'',​ but you want to place your ''​lscache''​ data on SSDs, such as ''/​ssdcache/​lscache''​. This requires a bit of special configuration both within your CacheRoot setting as well as CageFS.
 +
 +Make sure that your secondary disk is mounted on ''/​ssdcache''​ and that the directory ''​lscache''​ exists.
 +
 +Within ''/​etc/​apache2/​conf.d/​userdata/​lscache_vhosts.conf'',​ you'll have to add the following content:
 +
 +  <​IfModule Litespeed>​
 +  CacheRoot /​ssdcache/​lscache/​$vh_user
 +  </​IfModule>​
 +
 +The above 3 lines will tell LiteSpeed that the vhost-level cache corresponds to a dynamic LSCache folder which matches the user of the VirtualHost. This will ensure that the cache for each customer gets separated.
 +
 +If you're using CageFS, you also need to expose this within the caged environment. Luckily, it's rather easy to do!
 +
 +In your ''/​etc/​cagefs/​cagefs.mp''​ file, you can add the line:
 +
 +  %/​ssdcache/​lscache
 +
 +By using ''​%''​ in front of the path, it utilizes the "split by username"​ functionality added in CageFS 5.3.1, so what will be exposed within CageFS will be ''/​ssdcache/​lscache/​$user''​.
 +
 +To apply the above changes, we first rebuild the httpd configuration in cPanel and restart LiteSpeed:
 +
 +  /​scripts/​rebuildhttpdconf
 +  /​scripts/​restartsrv_httpd
 +
 +Afterwards, we have to remount CageFS for all users, so the new path becomes available within CageFS:
 +
 +  cagefsctl --remount-all
 +
 +Your LSCache data will now be stored on the SSD instead of your hard drive!
  • Admin
  • Last modified: 2021/10/06 15:20
  • by Lisa Clarke