Install WP-CLI on Cloudlinux with CageFS

If you manage your server, and in this case, it is CloudLinux, it is very likely that one of the advantages you enjoy is the CageFS system to cage each of the users and that the sites between them are not bothered.

But if you use WordPress in some of them and, for example, you want to configure the crones to run by the server, you will run into a small problem: CageFS and WP-CLI do not get along very well.

If you want to install it, you will have to follow some small steps, different from those that usually run:

cd ~
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
chown root:nobody wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp

So far the main difference with respect to the “manual” of WP-CLI is that we give [nobody] permissions to the file group. With this, later, any user will be allowed to run the global installation of WP-CLI.

The next step to perform is to configure the CageFS so that you can access to run WP-CLI:

vim /etc/cagefs/conf.d/wpcli.cfg

And we add the following content:

[wpcli]
comment=Permite ejecutar WP-CLI con CageFS
paths=/usr/local/bin/wp

And once we have saved, we will update the CageFS so that the WP-CLI can be executed.

cagefsctl --force-update

Theoretically, with this, if you enter by SSH in any user (even if you have the jailed activated) you can execute it… the problem comes when trying to configure the cron… although for this (without being the best option) we can call them for example, like this:

* * * * * WP_CLI_PHP=/usr/local/bin/php; SHELL=/bin/bash; /usr/local/bin/wp cron event run --due-now --path=/home/usuario/public_html/ >/dev/null 2>&1

You may receive some error message in the execution, but the crones are executed, which is the situation to be resolved.


About this document

This document is regulated by the EUPL v1.2 license, published in WP SysAdmin and created by Javier Casares. Please, if you use this content in your website, your presentation or any material you distribute, remember to mention this site or its author, and having to put the material you create under EUPL license.