Performance and monitoring

LiteMage Cache in Magento 2: install and configure

Reviewed on 3 min read performance LiteSpeed Cache Magento

LiteMage is the LiteSpeed module that replaces Magento 2's full page cache with the cache built into the LiteSpeed web server. Category and product pages are served directly by the server, and personal blocks (cart, customer) are loaded separately with ESI.

The module is free and our servers include LiteMage in their LiteSpeed licence, so you can install it straight away.

Before you start

  • Make a backup of your files and database: setup:upgrade modifies the database.
  • In Select PHP Version, check that you are using a PHP version compatible with your Magento and that memory_limit is at least 756M (what Magento 2.4 requires; for the compilation commands, 2G is better) and max_execution_time is at least 300.
  • You need SSH access or cPanel's Terminal.

1. Install the module

Connect over SSH, go to the Magento folder and put the shop into maintenance mode:

php bin/magento maintenance:enable

If the shop is in production mode, switch it to developer while you install:

php bin/magento deploy:mode:set developer

Install the module with Composer:

composer require litespeed/module-litemage

Enable it and recompile, running the commands one at a time and checking that each one finishes without errors:

php bin/magento module:enable Litespeed_Litemage
php bin/magento setup:upgrade
php bin/magento setup:di:compile

Switch back to production mode (this recompiles and deploys the static files) and turn off maintenance mode:

php bin/magento deploy:mode:set production
php bin/magento maintenance:disable

If a command fails, do not carry on with the next one: copy the error and restore the backup if the shop does not load.

2. Enable LiteMage in .htaccess

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

<IfModule LiteSpeed>
LiteMage on
</IfModule>

3. Select LiteMage as the cache

In the Magento admin, go to Stores > Configuration > Advanced > System, expand Full Page Cache and in Caching Application choose LiteMage Cache Built-in to LiteSpeed Server (untick Use system value first). Save.

Selecting LiteMage as the Caching Application in Magento

Then go to System > Cache Management, tick Configuration and Page Cache, choose Refresh and click Submit. Check that both show as ENABLED.

Refreshing Configuration and Page Cache in Magento's Cache Management

Check that it works

Open a category in a private window, press F12, go to Network and reload twice. On the HTML document, the X-LiteSpeed-Cache header should show hit,litemage from the second visit onwards.

Also try adding a product to the cart, logging in as a customer and changing language or currency if you use them.

To stop using LiteMage, set Caching Application back to Built-in Cache, refresh the cache, remove the block from .htaccess and then disable the module with php bin/magento module:disable Litespeed_Litemage.

You will find more options in the official LiteMage documentation.

You may also find useful

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