A menu-driven + direct command Bash toolbox to run WP-CLI tasks on servers (DirectAdmin / cPanel / system PHP) with:
- Automatic PHP detection (or choose a specific version)
- Auto-download of
wp-cli.phar - Runs WP-CLI with
--allow-root - Interactive menu for common WordPress operations
- Optional permissions & ownership fixes after sensitive operations
Run directly from GitHub (raw):
bash <(curl -Ls https://raw.githubusercontent.com/090ebier/wpcli-toolbox/refs/heads/main/wp-cli.sh)-
✅ Auto-detect PHP binaries:
- DirectAdmin:
/usr/local/php*/bin/php - cPanel:
/opt/cpanel/ea-php*/root/bin/php - System PHP:
phpin PATH
- DirectAdmin:
-
✅ Auto-selects the highest available PHP version
-
✅ Choose a specific PHP version via argument (e.g.
7.4,81,php74) -
✅ Interactive menu for most used WordPress maintenance tasks
-
✅ Direct command mode (run any WP-CLI command)
-
✅ Optional permissions fix:
- Directories:
755 - Files:
644 wp-config.php:600
- Directories:
-
✅ Attempts ownership fix (
chown -R user:user .) when possible
bashcurl- At least one
phpbinary available on the server - Recommended to run inside your WordPress directory (
public_html)
If you don’t have
root/sudo, ownership (chown) may fail and the script will warn you.
Run with no arguments:
./wp-cli.shIf multiple PHP versions are found, you’ll be asked to choose one.
Anything after the script name will be executed as a WP-CLI command.
Examples:
./wp-cli.sh core version --extra./wp-cli.sh plugin update --all./wp-cli.sh cache flushYou can specify a PHP version as the first argument. Supported formats:
74,7.4,php74,PHP7.481,8.1,php81
Examples:
Use PHP 7.4:
./wp-cli.sh 7.4 core versionUse PHP 8.1:
./wp-cli.sh 8.1 plugin update --allIf the requested version is not found, the script prints available versions.
The script prefers to run inside public_html. If you are not in a public_html directory, it warns you and asks whether to continue.
Expected paths:
/home/username/public_html/home/username/domains/example.com/public_html
It also tries to detect the system user from the current path to fix ownership automatically.
Some operations enable auto-fixing permissions after running WP-CLI:
- Directories:
755 - Files:
644 wp-config.php:600
Then it attempts:
chown -R user:user .If permissions do not allow ownership changes (no root/sudo), it shows a warning and continues.
./wp-cli.sh core download --version=latest --locale=fa_IR./wp-cli.sh core update./wp-cli.sh db export backup-$(date +%Y%m%d-%H%M%S).sql./wp-cli.sh db import backup.sql./wp-cli.sh search-replace old-domain.tld new-domain.tld --skip-columns=guid./wp-cli.sh plugin install contact-form-7 --activate./wp-cli.sh user update admin --prompt=user_pass-
This toolbox runs WP-CLI with
--allow-rootby design (useful for server administration/support environments). -
WP-CLI is downloaded to:
WPCLI_PATH="/tmp/wp-cli.phar"
-
The temporary file is removed on exit.
Make sure PHP exists on the server:
which php
php -vYou can continue, but best practice is:
cd /home/<user>/public_htmlYou likely need sudo/root permissions for chown.