The php command you type in the Terminal or over SSH is not required to be the version you chose for the site. The site uses what you set in Select PHP Version for that folder; the command line uses the first php it finds on the system path. So the site can be on 8.2 while php -v says something else. The fix is to call PHP by its full path, or make a shortcut.
Finding out which is which
| 1 |
Open the cPanel Terminal or an SSH session. Not every account has a shell; it depends on the account. The cPanel Terminal.
|
|
| 2 |
See the default PHP:php -v which phpThe first shows the version, the second where it comes from.
|
|
| 3 |
See the installed versions:ls -d /opt/alt/php*Each folder is a version: php82 is PHP 8.2, php74 is 7.4. If a folder does not show, that version is not available to you.
|
|
| 4 |
Call the version you want by its full path:/opt/alt/php82/usr/bin/php -vSwap 82 for your site’s version, without the dot.
|
|
| 5 |
Use that path in whatever you run:/opt/alt/php82/usr/bin/php artisan migrate /opt/alt/php82/usr/bin/php ~/composer.phar installThat way the command and the site speak the same language.
|
|
A shortcut so you do not type the path every time
If you work a lot on the command line, add a line to the account’s ~/.bashrc file:
alias php='/opt/alt/php82/usr/bin/php'Close and reopen the session, and php -v now shows the version you picked. The shortcut only works for whoever types in the Terminal: it does not work in cron, where you always write the full path (running a PHP script from a cron job).
Useful things on the command line
| Command |
What for |
| php -m |
Lists the extensions loaded in that version. Confirms that the one you switched on in Select PHP Version is really there. |
| php --ini |
Shows which configuration files PHP read. Useful when a value does not apply. |
| php -l file.php |
Checks a file’s syntax without running it. |
| php -d memory_limit=512M script.php |
Runs a script with one value changed for that run only. The account’s limits still apply. |
| php -r 'echo PHP_VERSION;' |
Prints the version that is running, so you are sure what the script uses. |
|
The command-line configuration may not be the site’s. A value set only in the site folder’s .user.ini applies to web requests and may not apply here. If the script fails on the command line and not in the browser (or the other way round), check the value with php -i on that same version. See viewing and adjusting your PHP configuration.
|
|
A version error from Composer or artisan is nearly always this. When a tool complains that PHP is too old and the site is already on a newer one, the command ran with the wrong PHP. Repeat it with the full path.
|
|
The command-line version still does not match? Tell us the account, the folder and what php -v shows.
Open a support ticket
|
RECOMMENDED PRODUCT VPS server with root access Resources of your own, the OS you choose, reinstall whenever you like. from $7.61/mo (3-year plan, with coupon) See plans |