Installing LiteSpeed Cache for Laravel

Installing LiteSpeed Cache for Laravel

Learn how to install LiteSpeed Cache for Laravel. The official package lets your Laravel project tell the server which pages to save and for how long. You can install it from the Laravel Toolkit in Plesk without using the command line.

Steps

  1. Log in to Plesk via your Zeniar Portal
  2. Select Websites & Domains from the left-hand menu
  3. Click Laravel under Dev Tools. If you have more than one domain, expand the domain you'd like to update first
  4. Click the Composer tab, enter require litespeed/lscache-laravel in the box and click Execute command
  5. Click the Artisan tab, enter the following in the box and run it
    vendor:publish --provider="Litespeed\LSCache\LSCacheServiceProvider"
  6. Select Files from the left-hand menu, open your project's public folder and click the .htaccess file. Add the following lines at the top and click Save
    <IfModule LiteSpeed>
    CacheLookup on
    </IfModule>
  7. Return to Laravel, click Edit next to Environment variables (.env), add the line LSCACHE_GUEST_ONLY=true and save. This keeps cached pages for visitors who are not logged in
  8. Add the cache setting to each route that is safe to save. In routes/web.php, a cached route looks like this
    Route::get('/about', [PageController::class, 'about'])->middleware('lscache:max-age=300;public');
  9. Check that the pages are being cached. See Checking Whether LiteSpeed Cache Is Working

Important: Nothing is cached until a route has the lscache setting. Only add it to pages that are the same for every visitor. Leave it off pages that show personal details and pages with forms, because a saved copy of a form carries the first visitor's security token and other visitors will see a 419 error when they submit it.

Please note: If you built the project with an AI tool, you can ask it: Add the lscache middleware with max-age=300;public to the public pages of this project, mark pages that need a login as lscache:no-cache, and call LSCache::purgeAll() whenever content is saved

Note: The Laravel Toolkit is not included with WordPress hosting plans.

Your Laravel project can now save pages in the LiteSpeed cache.

Other Setup