LSCache + TYPO3 Configuration

LSCache, similar to Varnish cache, is a simpler and more efficient page caching solution built-in to LiteSpeed Web Server. When used in conjunction with TYPO3, you can expect significant performance gains with a quick and easy setup. Cache management is also made significantly easier and more flexible. Rewrite rules can still be used to customize LSCache's behavior.

Below are some recommended configurations to enable LSCache and get it working with TYPO3 site(s).

Server/VirtualHost level cache storage needs to be configured properly for your environment. Select your server setup from the Web Server Configuration section of our LiteSpeed Cache Installation Guide and follow the instructions to set the server/virtual host level cache root and cache policy.

Rewrite rules should be added to your .htaccess file, located in the document root of your website. Add the following to the top of the .htaccess file:

########## Begin - Litespeed cache
<IfModule LiteSpeed>
  CacheLookup public on
  RewriteEngine On
  RewriteCond %{REQUEST_METHOD} ^GET|HEAD|PURGE$
  RewriteCond %{HTTP_HOST} ^domain.com [NC]
  RewriteCond %{REQUEST_URI} !typo3 [NC]
  RewriteRule .* - [E=Cache-Control:max-age=3600]
</IfModule>
########## End - Litespeed cache

Be sure to replace domain.com with the IP or Domain of the TYPO3 site. This line is not 100% needed, but does provide a safety net when caching multiple applications on the same vhost.

If the admin folder has changed from typo3 to something else, be sure to change typo3 to whatever it was changed to.

Open your browsers inspector, by right-clicking and selecting “Inspector” or pressing the F12 key, and refresh the page. Under the “Network” tab look for the HTML page you just loaded and click on it to view it's response header.

In the response header you should see X-LiteSpeed-Cache: hit to indicate that the page was served from cache successfully. If you see X-LiteSpeed-Cache: miss, reload the page and check again.

Note: LSWS will now delete expired cache files automatically, making this step optional. A cron job can still be set up to help ensure that the cache works as expected, clearing out pages that may have been misconfigured to have a very long TTL.

A cron job should be set to clear out old cache files that are past the set Time To Live (TTL).

To do this, you should run the crontab either as the root user or as the cache owner for self management.

crontab -e

The virtual host cache root directory is normally located in /home/$USER/lscache for shared hosting users or /tmp/diskspace for dedicated servers.

*/10 * * * * root find /virtualhost/cache/root/directory/ -type f -mmin +8 -delete 2>/dev/null

Note: This cron job deletes cached files that are more than 8 minutes old every 10 minutes. Since the cache TTL is set at 120 seconds (2 minutes), it is safe to delete these files as they are way past their TTL.

Admin Pages Still Being Cached After Setting Rewrite Rules

It is likely that LSCache is incorrectly enabled globally at the server level. This can be corrected either by changing the LSCache setting Enable Public Cache to “not set” or “no” as recommended here, or by disabling the setting for a particular virtual host by adding CacheDisable public / to their .htaccess file before any rewrite rules like so:

########## Begin - Litespeed cache
<IfModule LiteSpeed>
 RewriteEngine On
 CacheDisable public /
 RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
 RewriteCond %{ORG_REQ_URI} !typo3 [NC] 
 RewriteRule .* - [E=Cache-Control:max-age=120]
</IfModule>
########## End - Litespeed cache

Note: The “CacheDisable public /” directive is used to help protect against globally enabled caching. The Rewrite rules will enable caching as needed.

  • Admin
  • Last modified: 2017/04/25 20:59
  • by Michael Alegre