Performance and monitoring

LiteSpeed Cache for MediaWiki: install and configure

Reviewed on 3 min read performance LiteSpeed Cache

Our servers use LiteSpeed, which has a built-in page cache. The LiteSpeedCache extension for MediaWiki, made by LiteSpeed itself, connects the wiki to that cache: each page is generated once and the server serves subsequent visits directly. When someone edits an article, the extension purges only that page. It works with MediaWiki 1.25 and later.

1. Upload the extension

  1. Download the ZIP of the latest version from the extension's releases on GitHub.
  2. Unzip it on your computer. Inside you will find the LiteSpeedCache folder.
  3. Upload that folder to MediaWiki's extensions folder with cPanel's File Manager or over FTP. It should end up as extensions/LiteSpeedCache.

If you manage MediaWiki with Composer, you can install it with composer require litespeed/lscache-mediawiki from the wiki's folder.

2. Load it in LocalSettings.php

Edit LocalSettings.php and add this at the end:

wfLoadExtension('LiteSpeedCache');

To check that it has loaded, open Special:Version on your wiki: LiteSpeedCache should appear in the list of extensions.

3. Add the rule to .htaccess

Edit the .htaccess file in the MediaWiki folder and add this at the beginning:

<IfModule LiteSpeed>
CacheLookup on
</IfModule>

If you use the MobileFrontend extension, also add this block so that the mobile version is cached separately:

<IfModule LiteSpeed>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
RewriteRule .* - [E=Cache-Control:vary=ismobile]
RewriteRule .* - [E=Cache-Vary:stopMobileRedirect,mf_useformat]
</IfModule>

4. Enable the cache

Log in as an administrator and go to Special pages (Special:SpecialPages). In the Data and tools section you will find LiteSpeed Cache:

LiteSpeed Cache in MediaWiki's special pages

Click Edit and turn on LiteSpeedCache Enabled. From here you can also set how long pages are kept, enable the private cache for logged-in users and purge the whole cache.

LiteSpeed Cache extension settings in MediaWiki

Check that it works

Open a wiki page in a private window, press F12, go to Network and reload twice. On the HTML document, the X-LiteSpeed-Cache header should change from miss to hit. Edit a test page and check that the change is visible without logging in.

If the wiki is private (it can only be read with a user account), leave the public cache turned off and use only the private one.

To uninstall it, turn it off on its special page and remove the line from LocalSettings.php, the block from .htaccess and the extensions/LiteSpeedCache folder.

You may also find useful

Something wrong or out of date? Tell us and we will review it.