After upgrading to Ubuntu 16.04, php7 is installed out of the box. For my projects I use php5.6 . Tell me how to manage versions, and use php5.6 by default?

$ php -v PHP 7.0.6-1+donate.sury.org~xenial+1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies $ whereis php php: /usr/bin/php /usr/bin/php7.0 /usr/bin/php5.6 /usr/lib/php /etc/php /usr/share/php7.0-opcache /usr/share/php7.0-gd /usr/share/php /usr/share/php5.6-opcache /usr/share/php7.0-mcrypt /usr/share/php7.0-json /usr/share/php7.0-common /usr/share/php7.0-readline /usr/share/php5.6-json /usr/share/php7.0-xml /usr/share/php7.0-mysql /usr/share/php5.6-common /usr/share/php5.6-readline /usr/share/man/man1/php.1.gz 

    3 answers 3

    if these packages are installed from the official repository, then the alternatives mechanism (alternatives) is used and /usr/bin/php is a symbolic link (symlink) to /etc/alternatives/php , which, in turn, is also a symbolic link to the real executable file . in your case, /usr/bin/php7.0 .

    You can “redirect” to another alternative, for example, like this:

     $ sudo update-alternatives --config php 

    if there are alternatives, then a numbered list of alternatives (in particular, indicating the path to real files) will be offered with the proposal to enter a number (from the list) to change the current choice of alternative.

      already been. strange that they did not find. I use myself:

      Install from the official repository (7.0 and 5.6):

       sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0 

      and switch using the following commands for Apache and for the command line different !!!

      php5.6 -> php7.0:

      Apache:

       sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart 

      CLI:

       update-alternatives --set php /usr/bin/php7.0 

      php7.0 -> php5.6:

      Apache:

       sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart 

      CLI:

       sudo update-alternatives --set php /usr/bin/php5.6 

        Another option, phpenv as version manager:

        https://github.com/phpenv/phpenv

        • $(phpenv version-name) - current version of php;
        • ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - php.ini current version of php;
        • phpenv global 5.6.0 - use php version 5.6.0.