天天看点

php 安装zip,php zip拓展安装

在项目中使用PHPExcel时发现在调用save函数的时候报错

Message : Class 'ZipArchive' not found

Trace : /PHPExcel/Writer/Excel2007.php

经过一番查询之后发现是PHP没有安装zip拓展,于是乎前往下载编译源码资源libzip依赖、zip拓展。在这里我用的是libzip-1.2.0和zip-1.14.0的。

接下来就是编译依赖

[[email protected] ~]# tar zxvf libzip-1.2.0.tar.gz

[[email protected] ~]# cd libzip-1.2.0

[[email protected] ~]# ./configure

[[email protected] ~]# make & make install

安装完成之后编译php拓展

[[email protected] ~]# tar zxvf zip-1.14.0.tgz

[[email protected] ~]# cd zip-1.14.0/

[[email protected] ~]# phpize

[[email protected] ~]# make & make install

在执行make命令的时候,报错了

在包含自 /root/zip-1.14.0/php7/php_zip.h:31 的文件中,

从 /root/zip-1.14.0/php7/php_zip.c:31:

/usr/local/include/zip.h:59:21: 错误:zipconf.h:没有那个文件或目录

In file included from /root/zip-1.14.0/php7/php_zip.h:31,

from /root/zip-1.14.0/php7/php_zip.c:31:

/usr/local/include/zip.h:258: 错误:expected specifier-qualifier-list before ‘zip_int64_t’

In file included from /root/zip-1.14.0/php7/php_zip.h:31,

from /root/zip-1.14.0/php7/php_zip.c:31:

/usr/local/include/zip.h:285: 错误:expected specifier-qualifier-list before ‘zip_uint64_t’

/usr/local/include/zip.h:307: 错误:expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘zip_flags_t’

/usr/local/include/zip.h:309: 错误:expected declaration specifiers or ‘...’ before ‘*’ token

/usr/local/include/zip.h:309: 错误:expected declaration specifiers or ‘...’ before ‘zip_uint64_t’

/usr/local/include/zip.h:309: 错误:‘zip_int64_t’声明为返回一个函数的函数

/usr/local/include/zip.h:390: 附注:需要类型‘int (*)()’,但实参的类型为‘long int’

/root/zip-1.14.0/php7/php_zip.c:299: 错误:提供给函数‘zip_source_file’的实参太多

/root/zip-1.14.0/php7/php_zip.c:303: 错误:提供给函数‘zip_file_add’的实参太多

/root/zip-1.14.0/php7/php_zip.c: 在函数‘php_zipobj_get_zip_comment’中:

/root/zip-1.14.0/php7/php_zip.c:469: 错误:提供给函数‘zip_get_archive_comment’的实参太多

/root/zip-1.14.0/php7/php_zip.c: 在函数‘php_zipobj_get_zip_comment’中:

/root/zip-1.14.0/php7/php_zip.c:469: 错误:提供给函数‘zip_get_archive_comment’的实参太多

/root/zip-1.14.0/php7/php_zip.c:1345: 错误:‘struct zip_stat’没有名为‘name’的成员

/root/zip-1.14.0/php7/php_zip.c:1348: 错误:‘struct zip_stat’没有名为‘comp_size’的成员

/root/zip-1.14.0/php7/php_zip.c:1351: 错误:‘struct zip_stat’没有名为‘size’的成员

/root/zip-1.14.0/php7/php_zip.c:1354: 错误:‘struct zip_stat’没有名为‘comp_method’的成员

/root/zip-1.14.0/php7/php_zip.c:1385: 错误:‘struct zip_stat’没有名为‘comp_method’的成员

定位错误zipconf.h:没有那个文件或目录,看来是找不到配置文件了,于是乎手动转移zipconf.h

[[email protected] ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

[[email protected] ~]# make & make install

...

...

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts/

编译成功,接下来在php目录下的etc/php.ini配置文件追加extension=zip.so

然后重启nginx,重新载入php配置文件

[[email protected] ~]# service nginx restart

[[email protected] ~]# /etc/init.d/php-fpm reload

运行PHPExcel Demo成功,安装zip拓展成功。