• server
  • hacker
  • matrix
  • robot
  • web

Change the default PHP version on the server

Written by Mike Ennulat. Posted in Server-en

If you have installed multiple PHP versions, you may want to be able to change the standard version without much effort. Log in to your server via SSH and enter the following command in the command line:

sudo update-alternatives --config php

Now all installed versions are listed:

$ sudo update-alternatives --config php
There are 6 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php7.4   74        auto mode
  1            /usr/bin/php5.6   56        manual mode
  2            /usr/bin/php7.0   70        manual mode
  3            /usr/bin/php7.1   71        manual mode
  4            /usr/bin/php7.2   72        manual mode
  5            /usr/bin/php7.3   73        manual mode
  6            /usr/bin/php7.4   74        manual mode

Choose the desired version. Check with php -v if everything is correct. E.g. I chosed PHP 7.2:

$ php -v
PHP 7.2.31-1+ubuntu20.04.1+deb.sury.org+1 (cli) (built: May 14 2020 08:28:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.31-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

 

 

 

Tags: servers PHP update-alternatives default version