1. Home
  2. Technical
  3. How to change default php-cli in console

How to change default php-cli in console

Our platform uses at least 6 month old PHP stable version for it’s default in SSH php-cli.

You can check the current version used like this:

php -v

This gives the following answer:

virt490:sn-69-31.tll07.zoneas.eu:~> php -v
PHP 7.2.4 (cli) (built: May 3 2018 22:32:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.4, Copyright (c) 1999-2018, by Zend Technologies

For changing default version you need to create symlink to desired PHP version’s file in a ~/bin/ folder.

Path to the PHP CLI’s file in a server depends whether server is on ZoneOS platform or not.

The server’s platform can be known after establishing an SSH connection by looking at which name is among the information in the header:
– Operating System: ZoneOS
– DataZone Server Platform

Depending on the server platform, run one of the two commands for the required version of PHP CLI.

This is for example to use PHP 7.3:

mkdir -p ~/bin && ln -sf /usr/bin/php73-cli ~/bin/php

mkdir -p ~/bin && ln -sf /opt/zone/bin/php73-cli ~/bin/php

After running this command, re-login to SSH and after that php -v shows version 7.3.

If you need to run PHP 5.6 or 7.2 then you must create symlink to php56-cli or php72-cli.

NB! After creating this link, PHP CLI version will not change automatically in the future.
To remove the excising symlink run this command:

rm -f ~/bin/php
Updated on 2. Oct 2020

Was this article helpful?

Related Articles