//炬火不止,前进不息

PHP zip 扩展安装全记录

分类在 全部Linux计算机Centos其他相关PHP运维 0 评论

在升级图床过程中提示缺少 ZipArchive ,查了一下资料,发现由于编译时未加入 zip 扩展,需要安装 zip 扩展才能进行,这里进行一些记录。

下载源码

先到 PECL 查找下载最新源码,解压准备进行编译

# 截至 2020 年 8 月 17 日,zip 扩展最新稳定版本为 1.19.0
wget https://pecl.php.net/get/zip-1.19.0.tgz
tar -zxf zip-1.19.0.tgz
cd zip-1.19.0

生成 Makefile

# 运行 phpize 脚本,会根据 PHP 环境在目录下生成 configure 等文件
phpize
./configure

准备必要组件

安装 libzip

上一步报错,提示缺少 libzip

checking for libzip... not found
configure: error: Please reinstall the libzip distribution

安装 libzip-devel

dnf install libzip-devel
# 再次运行 ./configure
./configure

提示 libzip 版本过低,只好下载源码编译安装
前往 libzip.org 下载最新源码并解压

checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
# 卸载 libzip
dnf remove libzip-devel
# 截至 2020 年 8 月 17 日,libzip 最新稳定版本为 1.7.3
wget https://libzip.org/download/libzip-1.7.3.tar.gz
tar -zxf libzip-1.7.3.tar.gz
cd libzip-1.7.3

安装 cmake 进行

# 需要安装 cmake 继续
dnf install cmake
cmake .

提示 cmake 版本过低,得去下载源码编译安装
前往 cmake.org 下载最新源码并解压
(反复套娃)

CMake 3.0.2 or higher is required.  You are running version 2.8.12.2
# 卸载 cmake
dnf remove cmake
# 截至 2020 年 8 月 17 日,cmake 最新稳定版本为 3.18.1
wget https://github.com/Kitware/CMake/releases/download/v3.18.1/cmake-3.18.1.tar.gz
tar -zxf cmake-3.18.1.tar.gz
cd cmake-3.18.1
./configure
make && make install

万事俱备

继续前面的工作

# 编译 libzip
cd ..
# /zip-1.19.0/libzip-1.7.3
./configure
cmake .
make && make install
# 编译 zip 扩展
cd ..
## /zip-1.19.0
./configure
make && make install

配置 php.ini

编辑 php.ini 文件
在适当位置加入一行

extension=zip.so

重启 php-fpm 服务,检测是否生效

php -m | grep zip

疑难杂症

zip扩展安装后并没有生效
查找资料,参考这篇文章解决了问题,这里不再叙述
记录一次解决PHP Warning: PHP Startup: Unable to load dynamic library 'zip.so' libzip.so.5: cannot open

留言