We recently moved our websites from a Linux-Apache-MySQL-PHP (LAMP) server to individual OpenLiteSpeed servers. Hosting costs were one consideration, but it was mainly the performance boost that sold us on OpenLiteSpeed. One of the costs of moving is learning how to configure an unfamiliar server architecture. But then, learning new stuff can be beneficial as well. You probably agree, or you wouldn’t be reading this tutorial.
OpenLiteSpeed is similar to LAMP, so the configuration tasks are often identical, or nearly so. But there are some “gotchas,” such as the location of PHP. Depending on the version of PHP you are running, in OpenLiteSpeed the binary file is located at /usr/local/lsws/lsphp††/bin/lsphp
where ††
is the version number, e.g., if you are running PHP 7.3, the binary is located at /usr/local/lsws/lsphp73/bin/lsphp
.
The Problem with WordPress Cron
WordPress cron (WP-cron) does not run continuously. Instead, the wp-cron.php
runs every time a page loads. On high-traffic sites this can overwhelm server resources. Conversely, on low-traffic sites, schedules might easily be missed since no one has loaded a page.
To disable WP-cron and enable PHP cron:
- Add
define('DISABLE_WP_CRON', 'true');
towp-config.php
. - Edit the crontab for the www-data user:
- In the command line, enter
sudo crontab -u www-data -e
. This will open the editor. - Paste the following lines. Important! Replace †† with the actual PHP version number and replace
/path/to/wordpress/wp-cron.php
with the actual path to your wordpress installation.# WP cron disabled; using real cron via PHP instead. Runs every 5 minutes. */5 * * * * /usr/local/lsws/lsphp††/bin/lsphp /path/to/wordpress/wp-cron.php > /dev/null 2>&1 # Crontab must end on a blank line. Ensure that such a line exists after this comment
- In the command line, enter
- Save and exit the editor. PHP cron is now enabled.
If you need to test whether your cron job is working, follow these instructions, replacing PHP
with the file path to the real PHP executable.
Very nice, tks!
I’m not sure if anyone else runs into this problem but I could never find out why I kept getting high CPU load errors and usage reports all pointing to lsphp, the cache plugin that was supposed to help reduce server load. Every post I would find or forum topic I would read would often say that lsphp is not the culprit but likely a configuration that is making lsphp run in loops. In any case, I don’t have the capacity to resolve errors in configuration causing loops and from a small site owner perspective, I need my site to stop being restricted.
Your post helped me realize I had been using lsphp in the cron job which must’ve been from a tutorial long ago where I thought that properly pointing lsphp to the cron job would help alleviate the issue but it didn’t, it for the longest time, unknowingly kept reactivating LiteSpeed after I deactive it. It wasn’t until I came across your post to cross reference my own cron jobs as a double check as I try once again, for the millionth time, to resolve this high cpu load issue, and finally noticed one of my cron jobs for a WordPress site had `/opt/alt/php74/usr/bin/php` instead of the one mention for lsphp, or in my case that all my other sites used, `/usr/local/lsws/lsphp72/bin/lsphp`.
So if by chance you’re out there who are on a shared hosting server and run into high cpu usage issues when using this cron substitution AND your hosting plan has a Litespeed Cache plugin but you don’t want to use it to see if it will address the high CPU demand, then replace the lsphp binary with your regular php binary.
And, please correct me if I’m wrong, but I believe instead of redirecting the output, you can add the ‘-q’ option such that it might look something like:
`/opt/alt/php74/usr/bin/php -q /home/youresite.com/wp-cron.php`
Though, one mystery still remains is, why do I have so many php directories?!
“`
/opt/alt/php74/usr/bin/php
/usr/local/lsws/lsphp72/bin/lsphp
/usr/share/php
/usr/local/bin/php
“`
Are all real >_< Thank you for the how to check if cron is working link!
Wow! I’ve not run into that problem, but I’m glad my article helped you to solve it. Hopefully, anyone else with this error will see your comment and figure it out.
Regarding the multiple PHPs, your system PHP is different from the PHP that your server (in this case, OpenLitespeed) uses. To find out which one your server uses, create phpinfo.php and place it in your site root, then open https://my-site-url/phpinfo.php. To see which one your OS uses, run `which php`.