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

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

我遇到了问题,几个月前我将 ubuntu 14.04 更新到 16.04,我的 LAMP 的 php5.6 在 [=19= 旁边工作时出现问题],所以我删除了它。新项目现在很好,但是如果我尝试更新旧项目中的作曲家,控制台 returns 错误...内容如下:

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?怎么做?

只需使用 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>.

安装它们