Configuring mod_cdn with Litespeed

lucasrolff

Active Member
Staff member
#3
Hi @Émerson Felinto,

Even if you would use LiteSpeed Cache, you can automate it relatively easy by using WP-CLI, when the plugin is installed, you can get and set options within the plugin by using wp-cli lscache-admin get_options and set_options respectively.

So enabling CDN for a site could be something like:

Code:
wp-cli plugin install litespeed-cache --activate
wp-cli lscache-admin set_option cdn_ori //www.website.com
wp-cli lscache-admin set_option litespeed-cache-cdn_mapping[url][0] https://cdn.website.com
wp-cli lscache-admin set_option cdn true
wp-cli lscache-purge all
All it requires is that you have the CDN URL available, and the site URL available.

If using 1-click installer software, there's often a possibility to have hooks where you could execute the same commands, to make it happen during installation of WordPress for example.
 

lucasrolff

Active Member
Staff member
#5
With this command I will install WP-CLI on the site of all my clients ?
To install wp-cli, you can use the instructions here: https://make.wordpress.org/cli/handbook/installing/

If you then use CloudLinux and CageFS and want to make wp-cli available for your customers within their SSH / Terminal, you'd have to add wp-cli to the allowed list of commands they can run.

To make that happen, you create the file /etc/cagefs/conf.d/wpcli.cfg with the contents:

Code:
[wpcli]
comment=Allow wp-cli to work on the server
paths=/usr/local/bin/wp
After this, run cagefsctl --force-update to add the script to the CageFS filesystem.

If you use cPanel/WHM, I'd use the "Mass Enable Cache" functionality within the WHM plugin to install LiteSpeed Cache plugin for the WP sites.
The remaining 4 wp-cli commands, you could script it relatively easy, wp-cli has options to get the site URL for example:

Maybe something like this:
Code:
#/bin/bash

raw_domain=$(wp option get siteurl | cut -d'/' -f3) #get URL, split by / and get 3rd field

wp lscache-admin set_option cdn_ori //$raw_domain
wp lscache-admin set_option litespeed-cache-cdn_mapping[url][0] https://cdn.$raw_domain
wp lscache-admin set_option cdn true
wp lscache-purge all
 
Top