ubuntu-14.04ubuntu-16.04php-7php-5.6php-ini

How to install php5.6 in ubuntu 16.04 with php7?


I have got a problem, a few months ago I updated ubuntu 14.04 to 16.04, and my php5.6 from LAMP had problems working next to php7, so I removed it. New projects are fine now, but if I am trying to update composer in older projects, console returns error... Content below:

Problem 1
    - Installation request for simpay/api_client dev-master -> satisfiable by simpay/api_client[dev-master].
    - simpay/api_client dev-master requires ext-curl ^0.0.0 -> the requested PHP extension curl has the wrong version (7.0.8-0ubuntu0.16.04.3) installed.

  To enable extensions, verify that they are enabled in those .ini files:
    - /etc/php/7.0/cli/php.ini
    - /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
    - /etc/php/7.0/cli/conf.d/10-opcache.ini
    - /etc/php/7.0/cli/conf.d/10-pdo.ini
    - /etc/php/7.0/cli/conf.d/15-xml.ini
    - /etc/php/7.0/cli/conf.d/20-calendar.ini
    - /etc/php/7.0/cli/conf.d/20-ctype.ini
    - /etc/php/7.0/cli/conf.d/20-curl.ini
    - /etc/php/7.0/cli/conf.d/20-dom.ini
    - /etc/php/7.0/cli/conf.d/20-exif.ini
    - /etc/php/7.0/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.0/cli/conf.d/20-ftp.ini
    - /etc/php/7.0/cli/conf.d/20-gd.ini
    - /etc/php/7.0/cli/conf.d/20-gettext.ini
    - /etc/php/7.0/cli/conf.d/20-iconv.ini
    - /etc/php/7.0/cli/conf.d/20-json.ini
    - /etc/php/7.0/cli/conf.d/20-mbstring.ini
    - /etc/php/7.0/cli/conf.d/20-mysqli.ini
    - /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/7.0/cli/conf.d/20-phar.ini
    - /etc/php/7.0/cli/conf.d/20-posix.ini
    - /etc/php/7.0/cli/conf.d/20-readline.ini
    - /etc/php/7.0/cli/conf.d/20-shmop.ini
    - /etc/php/7.0/cli/conf.d/20-simplexml.ini
    - /etc/php/7.0/cli/conf.d/20-sockets.ini
    - /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.0/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.0/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.0/cli/conf.d/20-tokenizer.ini
    - /etc/php/7.0/cli/conf.d/20-wddx.ini
    - /etc/php/7.0/cli/conf.d/20-xmlreader.ini
    - /etc/php/7.0/cli/conf.d/20-xmlwriter.ini
    - /etc/php/7.0/cli/conf.d/20-xsl.ini
    - /etc/php/7.0/cli/conf.d/20-zip.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

It will be possible to install php5.6 without any problems? And make alias for example php5? How to do it?


Solution

  • Just install php5.6 with apt-get. I got my instructions from here. Be sure to use ondreij's ppa repository. This way php7.0 and php5.6 are installed side by side as completely separate packages.

    I am on a fresh 16.04 install. I installed php7.0 and all needed extensions. Today I installed php5.6 and made aliases to switch back and forth between the two versions. Put this in ~/.bash_aliases and reload it.

    alias enablephp5.6="sudo ln -s -f /usr/bin/php5.6 /etc/alternatives/php"
    alias enablephp7.0="sudo ln -s -f /usr/bin/php7.0 /etc/alternatives/php"
    

    So now when running php from console or when using composer install you can enable the correct version. It works perfectly for me.

    If you need additional php5.6 extensions just install them with sudo apt-get install php5.6-<extension>.