Categories: System Administration

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.

Surya

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.

Share
Published by
Surya

Recent Posts

How to get the all the database and table sizes of MySQL or MariaDB?

If you are working with MySQL or MariaDB web server, sooner or later you will…

7 years ago

How to set or change default text editor for crontab in Linux?

To edit the crontab entries you use crontab -e. The command will check for the…

7 years ago

How to install Comodo SSL certificate with NGNIX web server?

Installation method for COMODO SSL Certificate If you have generated the CSR and purchased or…

7 years ago

How to give access to specific users to specific buckets on AWS S3

In AWS S3, you might want to provide the access to selected users to selected…

7 years ago

How to add or change the password (passphrase) of OpenSSH key?

It's possible you have earlier generated a ssh key without password/ passphrase. Later you found…

7 years ago

How to find files on linux OS ( distributions )

If you are working on Linux OS, finding files effectively always a tricky part. Like…

7 years ago