如何在系统中安装几个php版本时使用pecl为特定的php版本安装php扩展?

时间:2021-02-03 00:00:22

I have installed both php5.6 and php7.0 from PPA on Ubuntu according to this manual

我根据本手册在Ubuntu上安装了PPA的php5.6和php7.0

http://lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu

But I didn't get how to install extensions using pecl for php5.6 or php7.0.

但我没有得到如何使用pecl for php5.6或php7.0安装扩展。

For example I have already installed version of libevent or amqp in php5.6.

例如,我已经在php5.6中安装了libevent或amqp的版本。

Now when I type pecl install libevent and my active php version is php7.0 (using update-alternatives --set php /usr/bin/php7.0),peclreturns message thatlibevent` already installed.

现在,当我输入pecl install libevent并且我的活动php版本是php7.0(使用update-alternatives --set php /usr/bin/php7.0)时,已经安装了speclreturns消息thatlibevent`。

But it was installed only for php5.6 (when this version was active) and now I want to do it for php7.0.

但它只安装了php5.6(当这个版本是活动的),现在我想为php7.0做。

Which commands could help me?

哪些命令对我有帮助?

UPD

I have found this commands for switch pecl to php7.0 and packet them to executable bash scripts:

我发现这个命令用于切换pecl到php7.0并将它们分发到可执行的bash脚本:

#!/bin/bash

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

sudo pecl config-set php_ini /etc/php/7.0/cli/php.ini
sudo pecl config-set ext_dir /usr/lib/php/20151012/
sudo pecl config-set bin_dir /usr/bin/
sudo pecl config-set php_bin /usr/bin/php7.0
sudo pecl config-set php_suffix 7.0

and for php5.6

并为php5.6

#!/bin/bash

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

sudo pecl config-set php_ini /etc/php/5.6/cli/php.ini
sudo pecl config-set ext_dir /usr/lib/php/20131226/
sudo pecl config-set bin_dir /usr/bin/
sudo pecl config-set php_bin /usr/bin/php5.6
sudo pecl config-set php_suffix 5.6

But they are not help, pecl still gives me list of already installed extensions to php5.6, even if I switched to php7.

但他们没有帮助,即使我切换到php7,pecl仍然给我已经安装的php5.6扩展列表。

pecl list
Installed packages, channel pecl.php.net:
=========================================
Package  Version State
amqp     1.7.1   stable
libevent 0.1.0   beta
stats    1.0.3   stable

It should be empty for php7.0 !

php7.0应该是空的!

How to solve the problem?

如何解决问题?

UPD

For amqp I have just installed php-amqp package without using pecl.

对于amqp我刚刚安装了php-amqp包而没有使用pecl。

apt-get install php-amqp

And libevent still not exists for php7. But I hadn't found a way to switch pecl installation between 5.6 and 7 version, so question is still open.

并且对于php7仍然不存在libevent。但是我没有找到一种方法来在5.6和7版本之间切换pecl安装,所以问题仍然存在。

3 个解决方案

#1


8  

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

在尝试编写脚本时,这对我来说最有效(如果有其他人像我一样遇到过这种情况):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

-d php_suffix = 部分允许您在运行时设置配置值与使用pecl config-set预先设置它们。卸载-r位实际上并没有卸载它(从文档中):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)

Options:
  ...
  -r, --register-only
        do not remove files, only register the packages as not installed
  ...

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

卸载行是必要的,否则安装它将删除任何以前安装的版本,即使它是针对不同的PHP版本(例如:如果软件包仍然注册为已安装,则安装PHP 7.0的扩展将删除5.6版本)。

#2


4  

I ran into this same issue while updating my Vagrant box with XHGui, as XHGui requires mongodb. I wanted to be able to support profiling on both PHP 5.6 and 7.0.

我在使用XHGui更新我的Vagrant框时遇到了同样的问题,因为XHGui需要mongodb。我希望能够支持PHP 5.6和7.0的分析。

I dug into the pecl source code, and found that there's a metadata_dir config option. That is a path to a directory where the current state of installed packages. Unfortunately, that isn't already namespaced per PHP version. If you try and set it with pecl config-set, you get an opaque 'failed' error. It turns out that setting isn't whitelisted as being configuable in the \PEAR_Config class:

我挖掘了pecl源代码,发现有一个metadata_dir配置选项。这是安装包的当前状态的目录的路径。不幸的是,每个PHP版本都没有命名空间。如果您尝试使用pecl config-set进行设置,则会出现不透明的“失败”错误。事实证明,设置未列入白名单,因为可以在\ PEAR_Config类中进行配置:

/**
 * Configuration values that can be set for a channel
 *
 * All other configuration values can only have a global value
 * @var array
 * @access private
 */
var $_channelConfigInfo = array(
    'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'cfg_dir',
    'test_dir', 'www_dir', 'php_bin', 'php_prefix', 'php_suffix', 'username',
    'password', 'verbose', 'preferred_state', 'umask', 'preferred_mirror', 'php_ini'
    );

In PECL's world, 'global' means it can only be set at install time, and not after.

在PECL的世界中,“全球”意味着它只能在安装时设置,而不能在安装时设置。

There's an issue in the PPA tracker over at github: https://github.com/oerdnj/deb.sury.org/issues/407

在github的PPA跟踪器中存在一个问题:https://github.com/oerdnj/deb.sury.org/issues/407

The final suggestion there is to build the extension manually for alternate PHP versions. I ended up using pecl for PHP 7 extensions, and manual builds for 5.6. Make sure you run update-alternatives for php-config and phpize, and not just php before building:

最后的建议是为备用PHP版本手动构建扩展。我最终使用pecl进行PHP 7扩展,并使用5.6进行手动构建。确保在构建之前运行php-config和phpize的update-alternatives,而不仅仅是php:

update-alternatives --set php /usr/bin/php5.6
update-alternatives --set php-config /usr/bin/php-config5.6
update-alternatives --set phpize /usr/bin/phpize5.6

Then, extract the extension and build it. These steps from the above issue worked for me with the mongodb extension:

然后,提取扩展并构建它。上述问题的这些步骤对我来说对mongodb扩展有用:

phpize5.6 && ./configure --with-php-config=php-config5.6 && make && sudo make install

phpize5.6 && ./configure --with-php-config = php-config5.6 && make && sudo make install

#3


3  

When pecl throws error is already installed and is the same as the released version

当pecl抛出错误已经安装并且与发布的版本相同

Switch to required php, php-config, phpize versions before installing from pecl

在从pecl安装之前切换到所需的php,php-config,phpize版本

Just run it installation with force flag

只需用force flag运行它就可以了

sudo pecl install -f <package-name>

#1


8  

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

在尝试编写脚本时,这对我来说最有效(如果有其他人像我一样遇到过这种情况):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

-d php_suffix = 部分允许您在运行时设置配置值与使用pecl config-set预先设置它们。卸载-r位实际上并没有卸载它(从文档中):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)

Options:
  ...
  -r, --register-only
        do not remove files, only register the packages as not installed
  ...

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

卸载行是必要的,否则安装它将删除任何以前安装的版本,即使它是针对不同的PHP版本(例如:如果软件包仍然注册为已安装,则安装PHP 7.0的扩展将删除5.6版本)。

#2


4  

I ran into this same issue while updating my Vagrant box with XHGui, as XHGui requires mongodb. I wanted to be able to support profiling on both PHP 5.6 and 7.0.

我在使用XHGui更新我的Vagrant框时遇到了同样的问题,因为XHGui需要mongodb。我希望能够支持PHP 5.6和7.0的分析。

I dug into the pecl source code, and found that there's a metadata_dir config option. That is a path to a directory where the current state of installed packages. Unfortunately, that isn't already namespaced per PHP version. If you try and set it with pecl config-set, you get an opaque 'failed' error. It turns out that setting isn't whitelisted as being configuable in the \PEAR_Config class:

我挖掘了pecl源代码,发现有一个metadata_dir配置选项。这是安装包的当前状态的目录的路径。不幸的是,每个PHP版本都没有命名空间。如果您尝试使用pecl config-set进行设置,则会出现不透明的“失败”错误。事实证明,设置未列入白名单,因为可以在\ PEAR_Config类中进行配置:

/**
 * Configuration values that can be set for a channel
 *
 * All other configuration values can only have a global value
 * @var array
 * @access private
 */
var $_channelConfigInfo = array(
    'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'cfg_dir',
    'test_dir', 'www_dir', 'php_bin', 'php_prefix', 'php_suffix', 'username',
    'password', 'verbose', 'preferred_state', 'umask', 'preferred_mirror', 'php_ini'
    );

In PECL's world, 'global' means it can only be set at install time, and not after.

在PECL的世界中,“全球”意味着它只能在安装时设置,而不能在安装时设置。

There's an issue in the PPA tracker over at github: https://github.com/oerdnj/deb.sury.org/issues/407

在github的PPA跟踪器中存在一个问题:https://github.com/oerdnj/deb.sury.org/issues/407

The final suggestion there is to build the extension manually for alternate PHP versions. I ended up using pecl for PHP 7 extensions, and manual builds for 5.6. Make sure you run update-alternatives for php-config and phpize, and not just php before building:

最后的建议是为备用PHP版本手动构建扩展。我最终使用pecl进行PHP 7扩展,并使用5.6进行手动构建。确保在构建之前运行php-config和phpize的update-alternatives,而不仅仅是php:

update-alternatives --set php /usr/bin/php5.6
update-alternatives --set php-config /usr/bin/php-config5.6
update-alternatives --set phpize /usr/bin/phpize5.6

Then, extract the extension and build it. These steps from the above issue worked for me with the mongodb extension:

然后,提取扩展并构建它。上述问题的这些步骤对我来说对mongodb扩展有用:

phpize5.6 && ./configure --with-php-config=php-config5.6 && make && sudo make install

phpize5.6 && ./configure --with-php-config = php-config5.6 && make && sudo make install

#3


3  

When pecl throws error is already installed and is the same as the released version

当pecl抛出错误已经安装并且与发布的版本相同

Switch to required php, php-config, phpize versions before installing from pecl

在从pecl安装之前切换到所需的php,php-config,phpize版本

Just run it installation with force flag

只需用force flag运行它就可以了

sudo pecl install -f <package-name>