在項目中使用PHPExcel時發現在調用save
函數的時候報錯
Message : Class 'ZipArchive' not found
Trace : /PHPExcel/Writer/Excel2007.php
經過一番查詢之后發現是PHP沒有安裝zip拓展,于是乎前往下載編譯源碼資源libzip依賴、zip拓展。在這里我用的是libzip-1.2.0和zip-1.14.0的。
接下來就是編譯依賴
[root@rhel6 ~]# tar zxvf libzip-1.2.0.tar.gz
[root@rhel6 ~]# cd libzip-1.2.0
[root@rhel6 ~]# ./configure
[root@rhel6 ~]# make & make install
安裝完成之后編譯php拓展
[root@rhel6 ~]# tar zxvf zip-1.14.0.tgz
[root@rhel6 ~]# cd zip-1.14.0/
[root@rhel6 ~]# phpize
[root@rhel6 ~]# 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
[root@rhel6 ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
[root@rhel6 ~]# 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配置文件
[root@rhel6 ~]# service nginx restart
[root@rhel6 ~]# /etc/init.d/php-fpm reload
運行PHPExcel Demo成功,安裝zip拓展成功。