php - 未找到 PECL libzip

标签 php pecl

我正在尝试使用 pecl 安装 zipArchive。运行命令后,我收到错误 - “请重新安装 libzip 发行版”。

我在 Amazon Linux 2 上运行 PHP 7.2。

这是我的输出:

$ ./pecl install zip
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading zip-1.15.2.tgz ...
Starting to download zip-1.15.2.tgz (249,280 bytes)
....................................................done: 249,280 bytes
8 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
building in /tmp/pear/install/pear-build-ec2-userIZcX1f/zip-1.15.2
running: /tmp/pear/install/zip/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep

...<snip up to warning>...

configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for zip archive read/writesupport... yes, shared
checking libzip... yes
checking PHP version... PHP 7.x
checking for pkg-config... /usr/bin/pkg-config
checking for libzip... not found
configure: error: Please reinstall the libzip distribution
ERROR: `/tmp/pear/install/zip/configure --with-php-config=/usr/bin/php-config' failed

但是如果我检查 libzip 它已经安装了:

$ sudo yum install libzip
Loaded plugins: langpacks, priorities, update-motd
amzn2-core                                                                                                                                     | 2.0 kB  00:00:00     
Package libzip-0.10.1-8.amzn2.x86_64 already installed and latest version
Nothing to do

我正在使用 ./pecl,因为我必须从我的主目录安装新版本的 pear,而旧版本仍在路径中。这是我用来获取 pear 更新版本的命令。

$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar

不知道这有什么区别吗?我的 php.ini 中确实有正确的版本:

;***** Added by go-pear
include_path=".:/home/ec2-user/pear/share/pear"
;*****

感谢任何帮助。

最佳答案

我已经成功编译了 PECL zip(部分原因是英国的雪取消了我预订的日子!)。我还没有在 php 中对此进行测试,但它可以正确加载到 phpinfo();

选项 1:更新 Libzip 并祝愿一切顺利

我使用了外部 CentOS-7 存储库(amzn linux 2 应该与之非常兼容)和以下脚本:

#PECL requires libzip 11 - get it from a foreign repo
sudo rpm --import http://wiki.psychotic.ninja/RPM-GPG-KEY-psychotic
#this looks wrong but the repo uses a single release
sudo rpm -ivh http://packages.psychotic.ninja/6/base/i386/RPMS/psychotic-release-1.0.0-1.el6.psychotic.noarch.rpm

#YUM REPO HACKS START
#unfortunately amazon-linux-2 release numbering breaks it - force RHEL 7 numbering
sudo sed -i s/\$releasever/7/g /etc/yum.repos.d/psychotic.repo
#Need to exclude outdated amzn zip packages
sudo yum remove libzip libzip-devel
#check for an exclude line, add our one if not present (to the main repo)
grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep exclude= || sudo sed -i -E "s/($(grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep -m1 ^name=)$)/\1\nexclude=libzip libzip-devel/" /etc/yum.repos.d/amzn2-core.repo
#check this worked, if not modify the existing exclude line(s)
grep -A 100 -m1 "\[amzn2-core" /etc/yum.repos.d/amzn2-core.repo | grep "exclude=.*libzip" || sudo sed -i -E "s/exclude=/exclude=libzip libzip-devel /" /etc/yum.repos.d/amzn2-core.repo
#YUM REPO HACKS END

sudo yum install --enablerepo=psychotic-plus gcc libzip libzip-devel
#now install PECL
wget http://pear.php.net/go-pear.phar
sudo php go-pear.phar
#patch it to cope with the XML being a module
sudo sed -i "$ s|\-n||g" /usr/bin/pecl
#and this should now work
sudo pecl install zip
#may still need to manually add to the php.ini
grep "^extension=zip.so" /etc/php.ini || echo "extension=zip.so" | sudo tee -a /etc/php.ini

要非常小心这个脚本中标记为“YUM REPO HACKS”的部分 - 它故意包含用于修改您的存储库配置的命令,这些命令经过了最少的测试。它实际上所做的就是用“7”替换 pyschotic 存储库中的“$releasever”变量,并将“exclude=libzip libzip-devel”添加到 amzn2-core 存储库中。你可以用 vim 做到这一点!

选项 2:2 个版本的 libzip

根据我的研究:如果您对服务器上的“found-by-google”存储库不满意(我不怪您,取决于用例),那么您可以保留 amzn zip,使用他们的源存储库来安装 libzip 11.2 源,将其(和/或其库)安装到备用位置(在其他位置找到相关说明)并手动编译 php 模块。

手动编译 zip:

$ pecl download zip
$ tar -xf zip-*.tgz && cd zip-* && phpize
$ ./configure --with-libzip=/path/to/secondary/libzip

...等等

关于php - 未找到 PECL libzip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48890287/

相关文章:

php - 使用数据透视表访问其他表信息

php - 在 Yii2 中输出关系数据

php - 在 MAMP 上安装 PECL

collections - 安装 PECL 包 : Mysql_xdevapi 时出错

php - : sudo pecl install mongodb 时出现 fatal error

php - 向表中插入数据并立即选择该行的ID号

php - 查询数据库来自

php - 在没有 GROUP BY 的聚合查询中,SELECT 列表的表达式 #2 包含非聚合列 'a.b.id' ;

php - 错误 1 ​​错误 : `make' failed when installing sqlsrv

php - 我使用 mailparse_msg_create 函数遇到 fatal error