Your site's running PHP 8.2 in MultiPHP Manager. Then you SSH in, type php -v, and it says 7.4. Or Composer refuses to install because "your PHP version does not satisfy that requirement", or a cron job that works fine in the browser dies with a syntax error. Nothing's broken on the site itself. The problem is that the command line and the web server are quietly using two different PHP binaries. Here's how to see which one is which, and how to make them agree.
Symptom: The Terminal and the Website Disagree About PHP
You'll usually notice one of these:
php -vover SSH or in cPanel Terminal shows an older (or newer) version than MultiPHP Manager.composer installfails withRoot composer.json requires php ^8.2 but your php version (7.4.33) does not satisfy that requirement.- A cron job emails you
PHP Parse error: syntax error, unexpected '?'orunexpected token "match"— modern syntax hitting an old interpreter. - WP-CLI or
php artisancomplains about a missing extension (intl,sodium,imagick) that the site clearly has. - Laravel says
Composer detected issues in your platformon the web, after you ran Composer from the shell.
Cause: Web PHP and CLI PHP Are Picked Differently
On a cPanel server, the website's PHP is chosen by a handler line that MultiPHP Manager writes into your .htaccess, something like:
# php -- BEGIN cPanel-generated handler, do not edit
<IfModule mime_module>
AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
The CLI doesn't read that for the site you're thinking of. The php you get in a shell is a cPanel wrapper (/usr/local/bin/php) that looks at the directory you're currently in and walks up looking for a handler. If you're sitting in ~ and your home directory has no handler, you get the server's system default version, which may be years behind what your public_html uses.
Cron makes this worse. Cron jobs start in your home directory, not in the site folder, so php script.php in a cron entry almost always gets the system default. And if your cron line calls /usr/bin/php directly, you're bypassing the directory logic entirely.
On CloudLinux servers there's a third layer: PHP Selector (alt-php) versions live under /opt/alt/phpXX/, and the web may use those while the shell uses EA-PHP.
Fix: First, Find Out What Each Side Is Using
Check the website side with a throwaway file. Create public_html/v.php:
<?php echo PHP_VERSION, ' | ', PHP_BINARY, ' | ', php_ini_loaded_file();
Load it in the browser, note the result, then delete it. Now check the shell side:
cd ~
php -v
which php
cd ~/public_html
php -v
ls /opt/cpanel/ | grep ea-php
If php -v changes between ~ and ~/public_html, the wrapper is doing its job and you just need to run commands from the right folder (or call the version explicitly). If it doesn't change, the wrapper isn't in play and you'll want the full binary path.
Fix: Call the Exact PHP Binary
The most reliable fix is to stop relying on php and name the binary. Each EasyApache 4 version has a fixed path:
| Version | EA-PHP binary (cPanel) | CloudLinux alt-php |
|---|---|---|
| PHP 8.1 | /opt/cpanel/ea-php81/root/usr/bin/php | /opt/alt/php81/usr/bin/php |
| PHP 8.2 | /opt/cpanel/ea-php82/root/usr/bin/php | /opt/alt/php82/usr/bin/php |
| PHP 8.3 | /opt/cpanel/ea-php83/root/usr/bin/php | /opt/alt/php83/usr/bin/php |
| PHP 8.4 | /opt/cpanel/ea-php84/root/usr/bin/php | /opt/alt/php84/usr/bin/php |
Only the versions actually installed on your server will exist, so check with ls before you copy a path. Then use it everywhere:
Cron jobs
# Before (gets the system default)
*/5 * * * * php /home/user/public_html/artisan schedule:run
# After (pinned to 8.2, runs from the right folder)
*/5 * * * * cd /home/user/public_html && /opt/cpanel/ea-php82/root/usr/bin/php artisan schedule:run >/dev/null 2>&1
Composer
Composer is just a PHP script, so it runs on whatever PHP launches it:
cd ~/public_html
/opt/cpanel/ea-php82/root/usr/bin/php /opt/cpanel/composer/bin/composer install --no-dev
If /opt/cpanel/composer/bin/composer isn't there, use which composer to find it, or download composer.phar into your home directory and run it the same way.
WP-CLI
WP-CLI respects an environment variable, which is handy:
export WP_CLI_PHP=/opt/cpanel/ea-php82/root/usr/bin/php
wp --info
The PHP binary line in wp --info should now show the 8.2 path.
Fix: Make the Shell Default Match Your Site
If you live in the terminal, pinning every command gets old. Add an alias to ~/.bashrc:
alias php='/opt/cpanel/ea-php82/root/usr/bin/php'
export WP_CLI_PHP=/opt/cpanel/ea-php82/root/usr/bin/php
Run source ~/.bashrc and check php -v. Keep in mind aliases don't apply in cron, so cron entries still need the full path.
Another option on cPanel: set the same version on your home directory in MultiPHP Manager (if your host exposes it), so the wrapper finds a handler no matter where you cd.
On a Plain VPS (No cPanel)
On Ubuntu or Debian with several PHP packages installed, the CLI follows the alternatives system while Nginx follows whatever PHP-FPM socket your server block points at. They drift apart easily after an upgrade.
# What the CLI uses
php -v
sudo update-alternatives --config php
# What the site uses
grep -R "fastcgi_pass" /etc/nginx/sites-enabled/
# e.g. unix:/run/php/php8.3-fpm.sock
Pick the matching number in update-alternatives, or call /usr/bin/php8.3 directly in scripts and cron. Also check extensions: installing php8.3-intl doesn't give php8.1 that extension, so the CLI and FPM can differ in modules even at the same major version.
Composer's Platform Check Gotcha
If you ran composer install under PHP 8.3 but the site runs 8.2, Composer may write a vendor/composer/platform_check.php that blocks the site. The clean fix is to rerun Composer with the site's PHP. To stop it from happening again, tell Composer what the production PHP is:
composer config platform.php 8.2.0
That's committed in composer.json, so every developer and every deploy resolves packages for 8.2, whatever PHP they happen to be on.
Prevention
- Never write a bare
phpin a cron job. Always use the full binary path. - When you change PHP in MultiPHP Manager, update your cron lines, aliases and deploy scripts in the same sitting.
- Pin
config.platform.phpincomposer.jsonto your production version. - Add a
php -vline at the top of deploy scripts so the log shows exactly which interpreter ran. - Remove test files like
v.phpas soon as you're done. They leak paths and versions to anyone who finds them.
Quick rule of thumb: if something works in the browser but fails from the shell or cron, check php -v before you touch the code.
Frequently Asked Questions
Why does php -v show a different version from MultiPHP Manager?
MultiPHP Manager sets the version for web requests through .htaccess. The shell's php wrapper picks a version based on your current directory, and falls back to the server's default if it finds no handler. Run php -v inside public_html or use the full /opt/cpanel/ea-phpXX/root/usr/bin/php path.
Can I change the server's default PHP version on shared hosting?
No, that's a server-wide setting in WHM and affects every account. You don't need to, though. Aliasing php in your ~/.bashrc and using full paths in cron gets you the same result for your account.
My cron job works when I run it by hand but fails in cron. Is this the reason?
Very often, yes. Cron starts in your home directory with a minimal environment, so it skips your aliases and usually gets the default PHP. Use the full binary path and cd into the project folder at the start of the cron line.
Will switching the CLI version affect my website?
No. Aliases, WP_CLI_PHP and full paths in cron only change what runs from the command line. The website keeps using whatever MultiPHP Manager (or your PHP-FPM pool on a VPS) is set to.
Which extensions does the CLI version have?
Run /opt/cpanel/ea-php82/root/usr/bin/php -m to list them. If one's missing compared to the site, it may come from a different php.ini; check php --ini for the loaded config files.
