Class ZipArchive not found, install the zip extension

When uploading an excel file and importing data, there is no problem in the local Windows development environment, but the server reports a Class ZipArchive not found error message.

The query found that on the Linux server, PHP lacks the zip extension. (php5.6 non-yum installation)

Install zip and depend on libzip

libzip download address: Download · libzip

Zip download address: http://pecl.php.net/package/zip

Download the extension pack:

# cd /usr/src/

// 这是当前libzip版本,但是里面没有 configure文件
// 在执行后续 生成 configure等文件时,有报错,无法生成,有时间等待后续研究
# wget https://libzip.org/download/libzip-1.7.1.tar.gz
If there is no configuration file, you can run ./configure to 
generate it.

Linux下各种依赖都已经安装,是因为没有找到makefile。

如果是自己写的,确定在当前目录下;如果是源码安装,先运行./configure,生成makefile,再执行make,即可正常运行。

I actually use the following libzip version, which contains a configure file, which can be run directly

# wget https://nih.at/libzip/libzip-1.2.0.tar.gz
# tar -zxvf libzip-1.2.0.tar.gz

# wget http://pecl.php.net/get/zip
# tar -zxvf zip

Enter the extension package, compile and install:

# cd libzip-1.2.0/
// 由于此包内,存在 configure等文件,可以直接进行编译安装
# make
# make install

// 若没有报错,进行下一步zip安装
# cd zip-1.21.0/
// 根据本机 php安装路径下phpize 来生成 configure等文件
# /www/server/php/73/bin/phpize

// 生成 configure等文件后,执行
# ./configure --with-php-config=/www/server/php/73/bin/php-config
// 执行后,进行编译
# make
# make install

When compiling the zip extension make, if   /usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or dire... prompt appears,  the zipconf.h file cannot be found

// 解决方法:直接手动复制过去即可
# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
// 再进行 编译和安装
# make && make install

After installation , the installation extension path will be prompted, such as: /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/zip.so

In the prompt path, find the zip.so extension and the installation is successful.

However, it does not mean that it can be used. Next, find the php.ini file to modify.

# Off changed to On 
zlib.output_compression = On 

# Add extension 
extension=/www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731/zip.so

After modifying  the php.ini  file, remember to restart the php service.

// Restart the php service 
# service php-fpm restart

Note: You can check  the location of the php.ini  file through phpinfo(), and check whether the zip and zlib extensions are installed successfully.

Guess you like

Origin blog.csdn.net/xgocn/article/details/126364151