Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Change the PHP version in CLI

Update 03/17/2026

This guide explains how to modify the PHP version used in the command line (PHP CLI) on an Infomaniak Web Hosting.

 

Preamble

  • Useful for configuring a specific script or PHP command line (CLI) session.
  • To modify the PHP version of the Web server (FPM/Apache) via the Manager, refer to this other guide.

 

Default PHP CLI version

The php command uses the default server version. Check the active version with this command:

# Check current PHP version
php -v

For the stability of your scripts, use an explicit path (e.g., php8.2) or modify your PATH variable.

 

Modify the PHP version in CLI

You can configure the PHP version automatically loaded in your SSH session via two main files.

 

1. Using .bashrc (Recommended)

The ~/.bashrc file is read when opening an interactive shell.

  1. Open the file (or create it if it does not exist):

    touch ~/.bashrc
    nano ~/.bashrc
  2. Add this line to define the desired version (example with PHP 8.3):

    export PATH="/opt/php8.3/bin:$PATH"
  3. Refresh the configuration:

    source ~/.bashrc
  4. Check the change:

    php -v
    which php

 

2. Using .profile (Alternative)

The ~/.profile file is read upon SSH connection (login mode).

  1. Modify the file:

    nano ~/.profile
  2. Add the export line:

    export PATH="/opt/php8.3/bin:$PATH"

 

3. Load .bashrc systematically

To apply the configuration to all types of sessions, add this code to your ~/.bash_profile or ~/.profile files:

# Load .bashrc if it exists
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

 

Run a specific version temporarily

To run a script with a specific version without changing your global environment, call the binary directly:

# Execute with a specific version
/opt/php8.2/bin/php my_script.php
/opt/php8.3/bin/php -v

Once these steps are completed, your SSH sessions and CLI scripts will use the selected PHP version by default.


Has this FAQ been helpful?