pecl 为以前的 php 版本安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19561722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:42:50  来源:igfitidea点击:

pecl installs for previous php version

phppearapcpeclosx-mavericks

提问by Rene Terstegen

I've upgraded my MacBook to Mavericks and ruined my development environment. The problem I have right now is that my pear/pecl still tries to install for my previous (5.3) version of PHP instead of version 5.4.

我已将 MacBook 升级到 Mavericks 并破坏了我的开发环境。我现在遇到的问题是我的 pear/pecl 仍然尝试为我以前的 (5.3) 版本的 PHP 而不是 5.4 版安装。

PHP version:

PHP版本:

$ php -v
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

Pear

$ pear version
PEAR Version: 1.9.4
PHP Version: 5.4.17
Zend Engine Version: 2.4.0
Running on: Darwin MBP-retina.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64

If I install apc with

如果我安装 apc

$ sudo pecl install apc
downloading APC-3.1.13.tgz ...
Starting to download APC-3.1.13.tgz (171,591 bytes)
.....................................done: 171,591 bytes
55 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
...
Build process completed successfully
Installing '/usr/local/Cellar/php53/5.3.26/include/php/ext/apc/apc_serializer.h'
Installing '/usr/local/Cellar/php53/5.3.26/lib/php/extensions/no-debug-non-zts-20090626/apc.so'
install ok: channel://pecl.php.net/APC-3.1.13
Extension apc enabled in php.ini

And enable the apc module in my php.ini php -v changes to this:

并在我的 php.ini 中启用 apc 模块 php -v 更改为:

$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20100525/apc.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/apc.so, 9): image not found in Unknown on line 0
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

So pecl installs my apc extension in /usr/local/Cellar/php53/5.3.26/lib/php/extensions/no-debug-non-zts-20090626and php expects it in /usr/lib/php/extensions/no-debug-non-zts-20100525/.

所以 pecl 将我的 apc 扩展安装/usr/local/Cellar/php53/5.3.26/lib/php/extensions/no-debug-non-zts-20090626/usr/lib/php/extensions/no-debug-non-zts-20100525/.

Simply making a symlink gives the following error:

简单地制作符号链接会出现以下错误:

$ php -v
PHP Warning:  PHP Startup: apc: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match
 in Unknown on line 0
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

So that's not a solution.

所以这不是一个解决方案。

Can anybody point me in the right direction? I really don't have a clue what is going on here.

有人能指出我正确的方向吗?我真的不知道这里发生了什么。

回答by Layke

In my case, I was attempting to install Gearman.

就我而言,我试图安装 Gearman。

pecl install gearman would install it incorrectly.

pecl install gearman 会错误地安装它。

php -iwould show:

php -i会显示:

PHP Extension => 20100525

Yet pecl would install using:

然而 pecl 会安装使用:

PHP Api Version:         20090626

After changing my config settings to use:

更改我的配置设置后使用:

First Fix

第一次修复

sudo pecl config-set php_ini /etc/php.ini
sudo pecl config-set php_bin /usr/bin/php5

I noticed that I would still get

我注意到我仍然会得到

WARNING: php_bin /usr/bin/php5 appears to have a suffix 5, but config variable php_suffix does not match

警告:php_bin /usr/bin/php5 似乎有后缀 5,但配置变量 php_suffix 不匹配

You can resolve this by using the config setting:

您可以使用配置设置解决此问题:

Additional Fix

附加修复

sudo pear config-set php_suffix 5


Why was this a problem?

为什么这是一个问题?

For me, I got into this problem because I added a custom PPA and reinstalled PHP. This meant that my previous install of php5-dev was out of sync.

对我来说,我遇到这个问题是因为我添加了一个自定义 PPA 并重新安装了 PHP。这意味着我之前安装的 php5-dev 不同步。

You if you ever get into the same situation, you might just want to run..

如果你遇到同样的情况,你可能只想跑..

apt-get remove php5-dev
pecl uninstall <extensionname>
apt-get install php5-dev
apt-get remove php5-pear
apt-get install php5-pear
pecl install <extensionname>

Alternatively, you can download the source and run phpize.

或者,您可以下载源代码并运行 phpize。

回答by Rene Terstegen

The solution was pretty simple. I had to make modifications to my pecl config. It turned out that these two command did the trick:

解决方案非常简单。我不得不修改我的 pecl 配置。事实证明,这两个命令可以解决问题:

sudo pear config-set php_ini /etc/php.ini
sudo pecl config-set bin_dir /usr/bin/

pecl used the wrong phpize. There were two versions of the phpize. The same counts for my php.ini file.

pecl 使用了错误的 phpize。phpize 有两个版本。我的 php.ini 文件也是如此。

回答by Ben Johnson

None of the other answers (as yet) seem to address having multiple "co-installable" PHP versions while wanting to build a given extension for all installed PHP versions.

其他答案(到目前为止)似乎都没有解决拥有多个“可共同安装”的 PHP 版本同时想要为所有已安装的 PHP 版本构建给定扩展的问题。

To illustrate the scenario in which I find myself (I'm using the Ondrej Sury PHP PPAs for Ubuntu 16.04 LTS):

为了说明我发现自己的场景(我使用的是 Ondrej Sury PHP PPA for Ubuntu 16.04 LTS):

root@localhost:~# ls -lah /usr/bin/*php*
-rwxr-xr-x  1 root   root     11K Apr 19 12:50 dh_php
-rwxr-xr-x  1 root   root    3.1K Apr  5  2016 dh_phpcomposer
-rwxr-xr-x  1 root   root    5.4K Apr  5  2016 dh_phppear
lrwxrwxrwx  1 root   root      21 Jul 24 00:44 php -> /etc/alternatives/php
-rwxr-xr-x  1 root   root    4.3M Jul  6 10:04 php5.6
-rwxr-xr-x  1 root   root    4.3M Jul  6 10:04 php7.0
-rwxr-xr-x  1 root   root    4.4M Aug  4 14:22 php7.1
lrwxrwxrwx  1 root   root      28 Jul 24 00:44 php-config -> /etc/alternatives/php-config
-rwxr-xr-x  1 root   root    4.3K Jul  6 10:03 php-config5.6
-rwxr-xr-x  1 root   root    4.1K Jul  6 10:03 php-config7.0
-rwxr-xr-x  1 root   root    4.1K Aug  4 14:21 php-config7.1
lrwxrwxrwx  1 root   root      24 Jul 24 00:44 phpize -> /etc/alternatives/phpize
-rwxr-xr-x  1 root   root    4.7K Jul  6 10:03 phpize5.6
-rwxr-xr-x  1 root   root    4.6K Jul  6 10:03 phpize7.0
-rwxr-xr-x  1 root   root    4.6K Aug  4 14:21 phpize7.1

pecl install extension-namedoes the job for PHP 7.1, but not the others.

pecl install extension-name为 PHP 7.1 完成这项工作,但不是其他的。

The other anwsers indicate that while it's possible to uninstall/reinstall php*-dev, I'd much rather not, given the intentional, co-installed PHP versions on the system.

其他回答者指出,虽然可以卸载/重新安装php*-dev,但考虑到系统上有意共同安装的 PHP 版本,我宁愿不这样做。

One solution is to build the extension for each version present on the system.

一种解决方案是为系统上存在的每个版本构建扩展。

This snippet demonstrates building with PHP 5.6, but I've done the same for 7.0 and 7.1 and the steps are the same.

此代码段演示了使用 PHP 5.6 进行构建,但我对 7.0 和 7.1 进行了相同的操作,并且步骤相同。

This example demonstrates cloning the extension from a Git repository, but one may use any source directory.

此示例演示从 Git 存储库克隆扩展,但可以使用任何源目录。

(#indicates that you must be root or use sudo)

(#表示你必须是root或使用sudo)

# apt-get install php-dev

# cd ~

# git clone https://github.com/vendor/extension-name

# cd ./extension-name

# phpize5.6

# ./configure --with-php-config=/usr/bin/php-config5.6

# make clean

# make

# make install

# ln -s /etc/php/5.6/mods-available/extension-name.ini /etc/php/5.6/fpm/conf.d/20-extension-name.ini

# service php5.6-fpm reload

回答by KorbenDallas

Better to reinstall phpize extensions as it will be used by PECL and not make hacks.

最好重新安装 phpize 扩展,因为它将被 PECL 使用而不是进行黑客攻击。

Do next (php 5.5 => php 5.6 example) :

下一步(php 5.5 => php 5.6 示例):

sudo apt-get remove php5-dev
sudo apt-get install php5.6-dev 

(you can change 5.6 to version you need)

(您可以将 5.6 更改为您需要的版本)

Then:

然后:

sudo pecl install extensionname

回答by Tobi G.

There is a way to switch PHP version on Ubuntu:

有一种方法可以在 Ubuntu 上切换 PHP 版本:

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

and optionally:

和可选:

sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6

Source: https://superuser.com/a/1100911/371795

来源:https: //superuser.com/a/1100911/371795

回答by Cédric

On Ubuntu 16.04, when using ppa:ondrej/php(and probably other alternatives), in order to install pecl/php extensions for php 5.6, you have to do the following:

在 Ubuntu 16.04 上,当使用ppa:ondrej/php(可能还有其他替代方案)时,为了为 php 5.6 安装 pecl/php 扩展,您必须执行以下操作:

pecl config-set ext_dir /usr/lib/php/20131226
pecl config-set php_bin /usr/bin/php5.6
pecl config-set php_ini /etc/php/5.6/cli/php.ini
pear config-set ext_dir /usr/lib/php/20131226
pear config-set php_bin /usr/bin/php5.6
pear config-set php_ini /etc/php/5.6/cli/php.ini
update-alternatives --config php #select php 5.6
update-alternatives --config php-config #select php 5.6
update-alternatives --config phpize #select php 5.6

Next you can use pecl as usual:

接下来你可以像往常一样使用 pecl:

pecl install raphf-1.1.2

downloading raphf-1.1.2.tgz ... Starting to download raphf-1.1.2.tgz (15,915 bytes) ......done: 15,915 bytes 8 source files, building

running: phpize

Configuring for:

PHP Api Version: 20131106

Zend Module Api No: 20131226

Zend Extension Api No: 220131226

...

install ok: channel://pecl.php.net/raphf-1.1.2

Extension raphf enabled in php.ini

正在下载 raphf-1.1.2.tgz ... 开始下载 raphf-1.1.2.tgz(15,915 字节)......完成:15,915 字节 8 个源文件,正在构建

运行: phpize

配置:

PHP API 版本:20131106

Zend 模块 API 编号:20131226

Zend扩展API编号:220131226

...

安装好:channel://pecl.php.net/raphf-1.1.2

在 php.ini 中启用扩展 raphf

I noticed that, when no extension are enabled in php.ini, pecl add the line extension="xxx.so"at the beginning of the php.ini, so I usually move it at the end of the file, manually, and after it's ok for the next extensions.

我注意到,当 php.ini 中没有启用扩展时,pecl 在 php.ini 的开头添加一行extension="xxx.so",所以我通常将它移动到文件的末尾,手动,然后再进行下一个扩展就可以了。

Depending of what you have on your system, it may be necessary to rollback your changes after install, especially for the default php version to use, with update-alternatives

根据您系统上的内容,可能需要在安装后回滚您的更改,尤其是对于要使用的默认 php 版本,以及 update-alternatives

回答by Shiji.J

Encountered similar problem recently.

最近遇到了类似的问题。

(Debian, PHP 7.3 just installed, was using PHP 7.2)

(Debian,刚刚安装了 PHP 7.3,正在使用 PHP 7.2)

If anybody tried the highest voted answer but still not working. Here are the steps to debug:

如果有人尝试了最高投票的答案但仍然无法正常工作。下面是调试步骤:

  • Remove all other php versions, especially the dev package (php7.2-dev in my case)
  • install the dev package for the current version (php7.3-dev)
  • 删除所有其他 php 版本,尤其是 dev 包(在我的例子中是 php7.2-dev)
  • 安装当前版本的开发包(php7.3-dev)

And basically that's it.

基本上就是这样。

Reason:

原因:

PECL requires phpize which is part of php-dev package. If phpize for the current version is not found, if will look for the previous version, which resulting a older PHP API number

PECL 需要 phpize,它是 php-dev 包的一部分。如果未找到当前版本的 phpize,则将查找以前的版本,这将导致较旧的 PHP API 编号