1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Changing the PHP version in CLI
This guide explains how modify PHP version directly in command line when you run PHP scripts using PHP CLI (Order Line Interface) on a Web hosting Infomaniak.
Preamble
- This can be useful when you need to temporarily change certain settings for a specific script or for a PHP session.
- If you only use the mention
php
below, it is the release before the one that was already in place that will be installed (last version -1): if the last version installed is 8.1, it is 8.0 that will be used with "php
"). Preference should be given to the indicationphp-7.0
,php-7.1
, etc. so that the version does not change as updates are made. - Be aware of this other guide if you are looking for information about the configuration of the PHP version defined on the Infomaniak Manager.
Edit PHP version used in CLI
It is possible to easily modify the PHP version used in command line (CLI) via SSH:
- Log in to the SSH server (Need help?).
Create a file
.profile
if there is no:touch ~/.profile
Edit file
.profile
:nano ~/.profile
Add this code inside the file to choose the desired php version:
export PATH=/opt/php7.4/bin:$PATH
Load file
.profile
:source ~/.profile
Check the version of php:
php -v
Interactive mode
The file .profile
mentioned above is only loaded when the user interface is used. In SSH ( login mode), this is the file .bash_profile
Who's psyched. And in interactive (non-login) mode, it's the file .bashrc
Who's psyched.
Some server deployment scripts open sessions in interactive mode ( non-login) and environment variables are not loaded into PATH even if the SSH session is properly configured.
In this case you have to load the php version in the file .bashrc
(export PATH="/opt/php7.4/bin:$PATH"
), and source in files >.bash_profile
and .profile
the file .bashrc
(. ~/.bashrc
).
After following these steps, the PHP version you have specified should be loaded into your shell environment every time you log in again. This will allow you to run scripts using this command line PHP (CLI) version.