Performance and monitoring

Set up LiteMage Cache in Magento 2

Reviewed on 4 min read rendimiento litespeed cache magento

LiteMage integrates Magento 2's full page cache with LiteSpeed Enterprise. The improvement depends on the catalogue, the pages that can be cached and the hit rate; it cannot be expressed as a fixed percentage.

The Magento extension is free, but it only works if the server has a LiteSpeed Enterprise licence with the LiteMage module enabled. Confirm this with support before you install it.

Before you start

  • Use a Magento 2 branch that is still supported and check its PHP, extension and Composer requirements.
  • Make a backup you can restore and rehearse the installation on staging.
  • Check that LiteMage is enabled on the server; installing the extension alone does not turn the cache on.

To install it you need SSH access and previous experience with the terminal.

Installation

Connect to the account over SSH and go to the Magento directory. Note the current deploy mode and use the PHP and Composer versions compatible with that installation. Schedule a maintenance window before changing a live store.

If Magento is in production mode, switch it temporarily to developer following Magento's official procedure. Then install the maintained package with Composer:

composer require litespeed/module-litemage

Run the following commands one at a time to enable the module and recompile the configuration files so that it is taken into account.

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

If the store was using production mode, switch it back when you finish. This command recompiles the dependencies, deploys the static content and clears the cache during the mode change:

php bin/magento deploy:mode:set production

Check that the command finishes without errors and that the storefront loads its resources before you reopen the store.

Finish by editing Magento's .htaccess file and adding the following lines at the top:

<IfModule LiteSpeed>
LiteMage on
</IfModule>

Getting it running

With LiteMage installed, open the Magento admin panel, go to Store > Configuration > Advanced > System and, if needed, change Full Page Cache so that LiteMage appears as the cache system in use.

Finally, go to System > Cache Management and refresh the Configuration and Page Cache caches, checking that both appear as enabled.

Verify and roll back

Without logging in, load a public page twice and check its headers in the browser's tools. LiteMage may show X-LiteSpeed-Cache: hit, litemage when it serves a cached response. Also check the cart, checkout, currencies, languages and two different customer sessions.

If the installation fails, do not carry on running the remaining commands. Keep the error and restore the previous deployment with its configuration. setup:upgrade can change the database: going back to the previous code does not undo those changes by itself. The recovery must respect any orders and writes made in the meantime.

To stop using LiteMage, first change the full page cache system following Magento's procedure, clear the cache and check the store before removing the extension. See the official LiteMage installation guide for the requirements and commands for your version.

You may also find useful

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