Skip to content

Install WP-CLI on cPanel and Run It as the Account User

Install WP-CLI on a cPanel server, either inside one account without root or server-wide as root, and confirm it works. Then run it as the account user, with the same PHP version as the website, so it doesn't leave files the site cannot change.

You have SSH or cPanel’s Terminal on a server that hosts WordPress, and you want the wp command working, either for your own account or for every account on the box. Getting a wp prompt is easy; the part that bites later is who runs it and with which PHP. Run as root, it leaves files the site can’t update. Run on the wrong PHP version, a plugin that works on the website crashes in the terminal. The answer is to check first whether WP-CLI is already installed, install the official package if not, and always run it as the account user on the PHP version the site uses.

What you’ll accomplish

  • A wp command that works for the account user, installed in your own ~/bin without root or once for the whole server.
  • A downloaded file you have checked against the project’s published checksum before running it.
  • WP-CLI running on the same PHP version as the website, with enough memory for large jobs.
  • A short habit that confirms which site a command will touch before it touches it.
  • For server admins, a way to act on an account’s site without writing files as root.

Prerequisites

  • A cPanel account with shell access. cPanel’s Terminal page only appears when the host enables “SSH Access & Terminal” for your package.
  • WordPress already installed. The examples use the account acme, the site in /home/acme/public_html and PHP 8.3, which cPanel calls ea-php83.
  • curl and sha512sum, present on any cPanel server.
  • For the server-wide install only: root on the server, through SSH or the Terminal page in WHM (WebHost Manager, the server-level side of cPanel).
  • WP-CLI needs PHP 7.2.24 or newer, according to the WP-CLI installation guide. Step 1 below shows which version your shell uses.

If you run CloudLinux with its own PHP Selector instead of cPanel’s MultiPHP, the binary paths below differ. The checks with wp --info still tell you what is running.

How it works

Three ways to run the same WP-CLI command on a cPanel account: as root, which leaves root-owned files the account cannot change; as the account user with plain wp, where the PHP version is uncertain; and as the account user through the site's own PHP binary, which matches the website

WP-CLI is one PHP file, a Phar archive (a PHP program packed into a single file) named wp-cli.phar. It has no daemon and no service. Each time you type wp, the shell starts PHP, PHP runs the archive, and the archive loads your WordPress as if a visitor had requested a page. Two things follow from that.

The command acts as whoever typed it. Every file it creates, whether a plugin, a cache file or an upload, belongs to that Unix user. On cPanel, the website runs as the account user. A plugin installed by root belongs to root, and the site can never update or delete it. WP-CLI knows this. Run as root, it stops with a message that starts YIKES! It looks like you're running this as root and only continues with --allow-root.

The command runs on whichever PHP the shell finds first. The first line of wp-cli.phar is #!/usr/bin/env php, so it uses the first php in your PATH. On cPanel that is usually /usr/local/bin/php, a wrapper from cPanel’s ea-php-cli package. The cPanel ea-php-cli documentation says it picks a version from the configured PHP path and falls back to the server default in /etc/cpanel/ea4/php.conf. That choice can differ from the version MultiPHP Manager assigns to your domain. When you call the site’s own PHP binary by its full path, there is nothing left to guess.

Each EasyApache 4 PHP version installs its command-line binary at /opt/cpanel/ea-phpXY/root/usr/bin/php, where XY is the version without the dot. cPanel also creates /usr/bin/ea-phpXY, but cPanel documents that link as calling php-cgi, the CGI (Common Gateway Interface) build meant for web servers. It prints HTTP headers before its output. Use the /opt/cpanel/... path for WP-CLI.

Step-by-step

  1. Check whether WP-CLI is already installed. Many cPanel hosts install it server-wide. Log in as the account user (cPanel’s Terminal does this for you) and run:

    command -v wp && wp --info

    Example output:

    /usr/local/bin/wp
    OS:	Linux 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 EST 2024 x86_64
    Shell:	/bin/bash
    PHP binary:	/opt/cpanel/ea-php81/root/usr/bin/php
    PHP version:	8.1.31
    php.ini used:	/opt/cpanel/ea-php81/root/etc/php.ini
    MySQL binary:	/usr/bin/mysql
    MySQL version:	mysql  Ver 15.1 Distrib 10.11.10-MariaDB, for Linux (x86_64) using readline 5.1
    SQL modes:
    WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:	phar://wp-cli.phar/vendor
    WP_CLI phar path:	phar:///usr/local/bin/wp
    WP-CLI packages dir:
    WP-CLI cache dir:	/home/acme/.wp-cli/cache
    WP-CLI global config:
    WP-CLI project config:
    WP-CLI version:	2.12.0

    If you see a path and a version, skip to step 4. If the command prints nothing, wp is not installed or not in your PATH; continue with step 2, or step 3 if you are root and want it for everyone. The output above already shows a common problem: PHP 8.1 on the command line while the site may run 8.3. Step 4 fixes that.

  2. Install it in your own account (no root needed). Download the official build and its checksum into ~/bin, then compare them:

    mkdir -p ~/bin && cd ~/bin
    curl -sSO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    curl -sSO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.sha512
    echo "$(cat wp-cli.phar.sha512)  wp-cli.phar" | sha512sum -c -

    Expected output:

    wp-cli.phar: OK

    OK means the file you downloaded is byte for byte the one the project published. FAILED means the download was cut short or altered; delete both files and download again. The .sha512 file holds only the hash, which is why the echo adds the file name. Then make it a command and check that your shell finds it:

    chmod +x wp-cli.phar && mv wp-cli.phar wp && rm wp-cli.phar.sha512
    echo "$PATH" | tr ':' '\n' | grep -x "$HOME/bin"

    Expected output:

    /home/acme/bin

    If the second command prints nothing, ~/bin is not in your PATH. Add it and reload the shell:

    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc

    Now command -v wp prints /home/acme/bin/wp. You own this copy, so wp cli update updates it later without root.

  3. Or install it server-wide (root). As root, download and check the same two files in a working directory, then install one copy for every account:

    cd /root
    curl -sSO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
    curl -sSO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.sha512
    echo "$(cat wp-cli.phar.sha512)  wp-cli.phar" | sha512sum -c -
    install -m 0755 wp-cli.phar /usr/local/bin/wp && rm wp-cli.phar wp-cli.phar.sha512
    su - acme -s /bin/bash -c 'command -v wp && wp cli version'

    Example output:

    wp-cli.phar: OK
    /usr/local/bin/wp
    WP-CLI 2.12.0

    The last line proves an account user, not only root, can run it. The -s /bin/bash option lets root open a shell for accounts whose login shell is disabled. Keep this copy current with wp cli update as root. WP-CLI exempts cli update and cli info from its root check so a root-owned install can be updated.

  4. Find the PHP version your site uses. In cPanel, open MultiPHP Manager. The PHP Version column shows the version for each domain, for example PHP 8.3 (ea-php83). Compare it with the PHP version line from step 1. If they match, you can stop here. If they differ, or if one account hosts sites on different versions, go on to step 5.

  5. Run WP-CLI on the site’s PHP. Confirm the binary exists, then point an alias at it:

    ls /opt/cpanel/ea-php83/root/usr/bin/php
    echo "alias wp='/opt/cpanel/ea-php83/root/usr/bin/php $(command -v wp)'" >> ~/.bashrc && source ~/.bashrc
    wp --info | grep -E '^PHP (binary|version)'

    Example output:

    /opt/cpanel/ea-php83/root/usr/bin/php
    PHP binary:	/opt/cpanel/ea-php83/root/usr/bin/php
    PHP version:	8.3.14

    The $(command -v wp) part is filled in once, when the line is written, so the alias holds the full path to your wp. Aliases only apply in interactive shells. In a cron job or script, write the full form, /opt/cpanel/ea-php83/root/usr/bin/php /home/acme/bin/wp .... The environment variable WP_CLI_PHP does not help here: the WP-CLI documentation says it only works for installs other than the Phar. If ls reports No such file or directory, that PHP version is not installed on the server; pick the version MultiPHP Manager shows.

  6. Check the memory limit WP-CLI gets. The command line reads the php.ini shown on the php.ini used line of wp --info. A limit you set for the website in cPanel’s MultiPHP INI Editor may not apply here. Check what PHP gives WP-CLI before WordPress loads:

    wp eval --skip-wordpress 'echo ini_get("memory_limit"), PHP_EOL;'

    Example output:

    128M

    128M is enough for most commands. Large imports, search-replace on a big database and media regenerate can stop with Allowed memory size of 134217728 bytes exhausted. For those runs, raise the limit for one command only, as the WP-CLI documentation suggests:

    /opt/cpanel/ea-php83/root/usr/bin/php -d memory_limit=512M "$(command -v wp)" --path=/home/acme/public_html media regenerate --yes

    -d changes the setting for this run and nothing else. If one site needs it every day, ask your host to raise memory_limit for the command line rather than raising it for every web request.

  7. Confirm who you are and which site you will touch. WP-CLI looks for WordPress in the current directory and the folders above it. On an account with an add-on domain or a staging copy, one wrong cd puts the next command on the wrong site. Before any command that changes something, run these three:

    id -un
    wp --path=/home/acme/public_html option get siteurl
    wp --path=/home/acme/public_html core version

    Example output:

    acme
    https://example.com
    6.8.3

    The user must be the account, never root. The URL must be the site you mean. If WP-CLI says This does not seem to be a WordPress installation, the path is wrong; ls /home/acme shows the folders the account has. Then keep --path= on every command, even when you are already in the right folder. It costs a few characters and it makes your shell history and logs say exactly which site each line touched.

  8. Make changes you can undo. Take a database export before anything that writes to the database, and preview any search-replace with --dry-run before the real run:

    wp --path=/home/acme/public_html db export ~/before-change-$(date +%F).sql
    wp --path=/home/acme/public_html search-replace 'http://example.com' 'https://example.com' --dry-run

    Example output:

    Success: Exported to '/home/acme/before-change-2026-10-28.sql'.

    The --dry-run prints a table of the rows each table would change and ends with Success: 312 replacements to be made. Read the counts, then run it again without --dry-run. Save the export outside public_html so a visitor can never download it. For updates, follow the order in updating WordPress with WP-CLI on cPanel. For the everyday commands themselves, the WP-CLI cheatsheet for cPanel lists them with their flags.

  9. As a server admin, act as the account, not as root. When you need to work on a client’s site from a root shell, switch to the account for that one command:

    su - acme -s /bin/bash -c 'wp --path=/home/acme/public_html plugin list --status=active'

    Files the command creates belong to acme, as if the client had run it. The alias from step 5 does not apply in this one-off shell, so put the full PHP path in front of wp when the versions differ. On servers with WP Toolkit, root can also run WP-CLI through the toolkit, which finds the site by its installation ID. Its documented form is wp-toolkit --wp-cli -instance-id 1 -- plugin list, and wp-toolkit --list shows the installations on the server. Avoid --allow-root on account files; reach for it only in a sandbox you will throw away.

Validate it works

Run this as the account user. Every line must match the site:

type wp
wp --info | grep -E '^(PHP version|WP-CLI version)'
wp --path=/home/acme/public_html option get siteurl
find /home/acme/public_html -user root 2>/dev/null | head -5

Example output:

wp is aliased to `/opt/cpanel/ea-php83/root/usr/bin/php /home/acme/bin/wp'
PHP version:	8.3.14
WP-CLI version:	2.12.0
https://example.com

The PHP version matches MultiPHP Manager, the URL is your site, and the find prints nothing, which means no file in the site belongs to root. If the alias line is missing, the shell did not read ~/.bashrc; log out and back in.

Troubleshooting

  • wp: command not found. The file is installed but not in your PATH. Run ls -l ~/bin/wp /usr/local/bin/wp to find it, then add its folder to PATH as in step 2. On CloudLinux servers with CageFS, the per-account cage that hides most of the server, a file root puts in /usr/local/bin may not be visible to accounts. The CloudLinux documentation describes adding a path through a new file in /etc/cagefs/conf.d/ and then running cagefsctl --update. A copy in ~/bin avoids the question entirely.
  • YIKES! It looks like you're running this as root. You are in a root shell. Leave it with exit and use the account, or wrap the command as in step 9. If root has already written files, find them with find /home/acme/public_html -user root and give them back with find /home/acme/public_html -user root -exec chown acme:acme {} +.
  • Output starts with X-Powered-By: and Content-type: text/html. You called /usr/bin/ea-php83, the CGI build. Use /opt/cpanel/ea-php83/root/usr/bin/php instead.
  • A plugin works on the site but WP-CLI shows a PHP fatal error. The command line is on a different PHP version, usually older. Compare wp --info with MultiPHP Manager, then apply step 5. The PHP CLI versus PHP-FPM version mismatch article covers the same split for cron jobs.
  • Allowed memory size of ... bytes exhausted. Rerun that one command with -d memory_limit=512M as in step 6. If it still runs out, the job is too large for one pass. Split it, for example by passing media regenerate a short list of attachment IDs at a time.

When this is the wrong approach

If your hosting package has no shell access, none of this applies. Use WP Toolkit or the WordPress dashboard, or ask the host to enable “SSH Access & Terminal”. For many servers at once, installing and calling WP-CLI by hand on each one does not scale; the remote WP-CLI over SSH patterns drive every server from one workstation instead. And if a host forbids anything in ~/bin, respect that and ask them for a server-wide install, since a policy usually exists for a reason you can’t see from inside one account.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.