linux系统扩展php的zip模块

问题:在虚拟机上导出excel文件和word文件时出现了以下的错误:

Fatal error:  Uncaught Error: Class 'ZipArchive' not found in /usr/local/httpd-2.4.18/htdocs/phpexcel/PHPExcel/Classes/PHPExcel/Writer/Excel2007.php:227

这个语法错误是因为php版本没安装zip这个扩展

相关文档:http://www.jb51.net/article/57082.htm

虚拟机上进行实践

下载对应的zip

[root@cqs htdocs]# cd /home/cqs/source/

[root@cqs source]# wget http://pecl.php.net/get/zip

[root@cqs source]# ls

 pgbouncer-1.5.4.tar.gz       postgis-2.1.6                   zip

#发现多了zip压缩包

[root@cqs source]# tar -zxvf zip #解压

[root@cqs source]# cd zip-1.13.2/ #进入对应的目录

[root@cqs zip-1.13.2]# phpize #执行这个命令报错

-bash: phpize: command not found

#经查找资料,phpize这个命令是phpLinux系统中的,所以使用时要打印出对应的完整路径或者配置默认路径

[root@cqs zip-1.13.2]# /usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20151012

Zend Module Api No:      20151012

Zend Extension Api No:   320151012

[root@cqs zip-1.13.2]# ./configure #配置路径,报错

configure: error: Cannot find php-config. Please use --with-php-config=PATH

解决方案:

[root@cqs zip-1.13.2]# ./configure --with-php-config=/usr/local/php/bin/php-config

[root@cqs zip-1.13.2]# make #编译

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

Build complete.

Don't forget to run 'make test'

[root@cqs zip-1.13.2]# make install

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

由此安装成功了

配置php.ini

新增

;对应的zip.so对应的

extension = /usr/local/php/lib/php/extensions/no-debug-zts-20151012/zip.so 

zlib.output_compression = Off 改为zlib.output_compression = On

重启apache服务

 [root@cqs bin]# /usr/local/httpd-2.4.18/bin/apachectl restart

发现语法错误解决了

而在导出word文件时需要打开模板文件,这时候又出现了failed to open stream: Permission denied 这个语法错误,可见是由于权限问题,修改对应文件的权限

[root@cqs htdocs]# chmod 777 phpexcel/

至此,问题解决了

你可能感兴趣的:(linux,php)