2.8.7. Change PHP version for console
View the current version
The command to view the current PHP version:
php -v
Change version
Through the control panel
- Open the section "Hosting → Linux configuration".
- In the block "PHP version" select the version you want and click "Save":
- Execute the command
source ~/.bashrc
or. ~/.bashrc
, or just reconnect via SSH.
The installed version will be valid for all new SSH connections.
Explicitly specifying the interpreter
When executing commands, explicitly specify the path to the PHP interpreter of the required version:
/usr/local/php4/bin/php /usr/local/php52/bin/php /usr/local/php53/bin/php /usr/local/php54/bin/php /usr/local/php55/bin/php /usr/local/php56/bin/php /usr/local/php70/bin/php /usr/local/php71/bin/php /usr/local/php72/bin/php /usr/local/php73/bin/php /usr/local/php74/bin/php /usr/local/php80/bin/php /usr/local/php81/bin/php /usr/local/php82/bin/php
Or use shortened links like /usr/bin/php8.2
or simply php8.2
(insteadof 8.2
specify the correct version).
Alias creation
Attention!
To work with Composer use the version change method via control panel or overriding PATH. Also aliases are not suitable for use in PHP scripts, Bash scripts and cron — in them, be sure to indicate the full the absolute path to the PHP interpreter the version you want.- Open the section "Hosting → Linux configuration".
- In the block "Aliases" in the first field specify
php
, in the second — the command/usr/local/php82/bin/php
(insteadofphp82
specify the desired version) and click "Save": - Execute the command
source ~/.bashrc
or. ~/.bashrc
, or just reconnect via SSH.
Overriding PATH
Override the variable PATH
by running the command (in the command, replace php82
to the required PHP version):
export PATH=/usr/local/php82/bin:$PATH
The installed version will only work for the current SSH connection. To make the version work for new connections, use the change version method via control panel.