Changing the WP CLI cache folder

As a highly concerned hosting company owner I am using WP-CLI to update plugins, themes and wp core of my clients.

Updating WP-Core

find /home/*/public_html -name "wp-admin" -execdir /home/wp core update --allow-root \;

Updating Plugins

find /home/*/public_html -name "wp-admin" -execdir /home/wp plugin update-all --allow-root \;

Updating Themes

find /home/*/public_html -name "wp-admin" -execdir /home/wp theme update-all --allow-root \;

Everything is working extremely well, but I want just to change CACHE folder for WP-CLI since I do not want it to store in /root/wp-cli/.cache

It's actually not storing anything there because I enabled Open base dir, how can I change location of cache folder for wp cli? is there a syntax? I can't find any docs on it

PHP Warning:  file_exists(): open_basedir restriction in effect. File(/root/.wp-cli/cache/) is not within the allowed path(s): (/home:/tmp:/opt/cpanel/composer/bin/composer) in phar:///home/wp/php/WP_CLI/FileCache.php on line 261

I honestly do not know what is cache folder used for but since wp cli can't use it I am just afraid that something will fail, but so far it didn't.

Topic wp-cli shared-hosting maintenance Wordpress

Category Web


This is actually how I ended up doing this, this is a script I wrote for updating themes, plugins and wp core on cPanel servers

#!/bin/bash

rm -rf /home/wp
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /home/wp
chmod +x /home/wp
sleep 5

Red='\033[0;31m'
Color_Off='\033[0m'

echo -e "$Red Updating WP core $Color_Off";

for i in `ls /var/cpanel/users/`; do sudo -H -u $i cp /home/wp /home/$i/wp && sudo -H -u $i find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/$i/wp core update \; && sudo -H -u $i rm -rf /home/$i/wp ; done

echo -e "$Red Updating plugins $Color_Off";

for i in `ls /var/cpanel/users/`; do sudo -H -u $i cp /home/wp /home/$i/wp && sudo -H -u $i find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/$i/wp plugin update-all \; && sudo -H -u $i rm -rf /home/$i/wp ; done

echo "$Red Updating themes $Color_Off";

for i in `ls /var/cpanel/users/`; do sudo -H -u $i cp /home/wp /home/$i/wp && sudo -H -u $i find /home/$i/public_html -name 'wp-admin' -execdir /usr/local/bin/php /home/$i/wp theme update-all \; && sudo -H -u $i rm -rf /home/$i/wp ; done

You could try to change it through the environment variable:

WP_CLI_CACHE_DIR

as we have it included in the WP_CLI::get_cache() method (src):

$dir = getenv( 'WP_CLI_CACHE_DIR' ) ? : "$home/.wp-cli/cache";

You can also check out issue #1848 - Use shared cache directory for multiple installs for usage examples.

In the WP-CLI Handbook on make.wordpress.org, we have a list of environment variables used by WP-CLI.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.