如何用php7在ubuntu 16.04中安装php5.6?

时间:2017-01-10 12:58:47

标签: ubuntu-14.04 ubuntu-16.04 php-7 php-5.6 php-ini

我有一个问题,几个月前我将ubuntu 14.04更新到16.04,而我的php5.6来自LAMP,在php7旁边工作时遇到了问题,所以我删除了它。新项目现在很好,但如果我想在旧项目中更新作曲家,控制台会返回错误......下面的内容:

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.

可以安装php5.6没有任何问题吗?并制作别名,例如php5?怎么做?

1 个答案:

答案 0 :(得分:4)

只需使用apt-get安装php5.6即可。我从here收到了我的指示。 一定要使用ondreij的ppa存储库。这样php7.0和php5.6并排安装为完全独立的软件包。

我正在安装16.04。我安装了php7.0和所有需要的扩展。今天我安装了php5.6,并在两个版本之间来回切换。把它放在〜/ .bash_aliases中并重新加载。

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"

现在,当从控制台运行php或使用composer install时,您可以启用正确的版本。它对我来说很完美。

如果您需要额外的php5.6扩展程序,只需使用sudo apt-get install php5.6-<extension>安装它们。