Linux – How to set default version of PHP in Ubuntu 16.04

It might be possible you have installed multiple version of PHP in you server or system. First you should list all the php version and check which version is set to default. After that set the preferred PHP version.

How to list number of Php version in the system?

To list PHP version use sudo update-alternatives --display php

surya@x:$ sudo update-alternatives --display php
php - manual mode
  link best version is /usr/bin/php7.1
  link currently points to /usr/bin/php5.5
  link php is /usr/bin/php
  slave php.1.gz is /usr/share/man/man1/php.1.gz
/usr/bin/php5.5 - priority 55
  slave php.1.gz: /usr/share/man/man1/php5.5.1.gz
/usr/bin/php5.6 - priority 56
  slave php.1.gz: /usr/share/man/man1/php5.6.1.gz
/usr/bin/php7.0 - priority 70
  slave php.1.gz: /usr/share/man/man1/php7.0.1.gz
/usr/bin/php7.1 - priority 71
  slave php.1.gz: /usr/share/man/man1/php7.1.1.gz

How to check current default Php version in server?

To check current default version use command php -v

surya@x:$ php -v
PHP 5.5.38-4+deb.sury.org~xenial+1 (cli) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

How to set default Php version in server?

To set default version of PHP use sudo update-alternatives --config php

surya@x:$ sudo update-alternatives --config php
There are 4 choices for the alternative php (providing /usr/bin/php).

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

Press <enter> to keep the current choice[*], or type selection number: 2       
update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode


surya@OMDELPDNEOUBU:/etc/nginx/sites-available$ php -v
PHP 5.6.31-4+ubuntu16.04.1+deb.sury.org+4 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

This is how, you can set your preferred version of Php to the system.

Living in permanent beta mode: Learning, Improving & evolving. SPECIALTIES: Web Application Development, Digital Media, E-Commerce Solutions, SEO, CRM Solutions, Open Source Technologies, System Administration ( Linux ), VOIP Solutions, Cloud Computing, Web Security.

Leave a reply:

Your email address will not be published.

Site Footer