PHP:Add Zip Extension
Situation:
可能,你也会遇到上图的情况:
在部署某个WEB APP的时候,被应用告知,应用服务器缺少某个扩展支持。
在这里,缺少的是“zip module”。
——————————
(下面予以解决。)
ZIP的扩展的意义在于,它可以让你透明的读写ZIP压缩文档以及ZIP压缩文件内部的文件。
PHP官方的文档说明中关于ZIP的部分:http://php.net/zip
获取最新的ZIP包:http://pecl.php.net/package/zip
最新版是:1.12.4,2014年1月29日发布的。
下载直链为:http://pecl.php.net/get/zip-1.12.4.tgz
上传服务器,并解压:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@center ~]# cd /software/owncloud/ [root@center owncloud]# ls owncloud owncloud-7.0.3.tar zip-1.12.4.tgz [root@center owncloud]# gunzip zip-1.12.4.tgz [root@center owncloud]# ls owncloud owncloud-7.0.3.tar zip-1.12.4.tar [root@center owncloud]# tar -xf zip-1.12.4.tar [root@center owncloud]# ls owncloud owncloud-7.0.3.tar package.xml zip-1.12.4 zip-1.12.4.tar [root@center owncloud]# cd zip-1.12.4 [root@center zip-1.12.4]# ls config.m4 config.w32 CREDITS examples lib LICENSE LICENSE_libzip php_zip.c php_zip.h tests zip_stream.c [root@center zip-1.12.4]# |
在我的环境中,PHP被安装在:/usr/local/php
与PHP相关的扩展包位于:$PHP_HOME/include/php/ext
1 2 3 4 5 6 |
[root@center ext]# pwd /usr/local/php/include/php/ext [root@center ext]# [root@center ext]# ls date dom ereg filter gd hash iconv json libxml mbstring mysqli mysqlnd pcre pdo phar session simplexml sockets spl sqlite3 standard xml [root@center ext]# |
阶段:Configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
[root@center zip-1.12.4]# pwd /software/owncloud/zip-1.12.4 [root@center zip-1.12.4]# ls config.m4 config.w32 CREDITS examples lib LICENSE LICENSE_libzip php_zip.c php_zip.h tests zip_stream.c [root@center zip-1.12.4]# [root@center zip-1.12.4]# /usr/local/php/bin/phpize configure --with-php-config=/usr/local/php/bin/php-config Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@center zip-1.12.4]# [root@center zip-1.12.4]# ./configure --with-php-config=/usr/local/php/bin/php-config checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for PHP prefix... /usr/local/php checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-zts-20131226 checking for PHP installed headers prefix... /usr/local/php/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk... gawk checking for zip archive read/writesupport... yes, shared checking for the location of libz... no checking pcre install prefix... no checking libzip... no checking for the location of zlib... /usr checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for int8_t... yes checking for int16_t... yes checking for int32_t... yes checking for int64_t... yes checking for uint8_t... yes checking for uint16_t... yes checking for uint32_t... yes checking for uint64_t... yes checking for ssize_t... yes checking size of short... 2 checking size of int... 4 checking size of long... 8 checking size of long long... 8 checking size of off_t... 8 checking size of size_t... 8 checking for touch... /bin/touch checking for unzip... /usr/bin/unzip checking whether struct tm is in sys/time.h or time.h... time.h checking for struct tm.tm_zone... yes checking for ld used by cc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes checking how to recognize dependent libraries... pass_all checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking the maximum length of command line arguments... 98304 checking command to parse /usr/bin/nm -B output from cc object... ok checking for objdir... .libs checking for ar... ar checking for ranlib... ranlib checking for strip... strip checking if cc supports -fno-rtti -fno-exceptions... no checking for cc option to produce PIC... -fPIC checking if cc PIC flag -fPIC works... yes checking if cc static flag -static works... yes checking if cc supports -c -o file.o... yes checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no creating libtool appending configuration tag "CXX" to libtool configure: creating ./config.status config.status: creating config.h [root@center zip-1.12.4]# |
先查看下安装介质的“modules”目录的状态:
1 2 |
[root@center zip-1.12.4]# ls modules/ [root@center zip-1.12.4]# |
在接下来的“make”完成后,会在“modules/”中生成:zip.so。
阶段:make
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@center zip-1.12.4]# make (... ...etc) ---------------------------------------------------------------------- Libraries have been installed in: /software/owncloud/zip-1.12.4/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' 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@center zip-1.12.4]# |
“make”完成后的“modules”目录状态:
1 2 3 |
[root@center zip-1.12.4]# ls /software/owncloud/zip-1.12.4/modules zip.la zip.so [root@center zip-1.12.4]# |
阶段:“make install”
1 2 3 4 5 6 |
[root@center zip-1.12.4]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ [root@center zip-1.12.4]# [root@center zip-1.12.4]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ opcache.so zip.so [root@center zip-1.12.4]# |
将上面make阶段生成的zip.so,拷贝到“make install”阶段反馈的目录中,如果重名,覆盖之。
1 2 3 |
[root@center zip-1.12.4]# cp /software/owncloud/zip-1.12.4/modules/zip.so /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ cp: overwrite `/usr/local/php/lib/php/extensions/no-debug-zts-20131226/zip.so'? y [root@center zip-1.12.4]# |
修改PHP的配置文件:php.ini。
1 2 3 4 5 6 |
[root@center php]# pwd /usr/local/php [root@center php]# cat etc/php.ini | grep -v "^;" | grep --color extension extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226/" extension=zip.so [root@center php]# |
重启Apache服务:
1 2 |
[root@center php]# /usr/local/apache/bin/apachectl restart [root@center php]# |
查看:phpinfo()的内容,你会发现增加了对ZIP的支持:
这部分信息,在之前是没有的。
这次,没有关于缺失PHP扩展包的报错了。
————————————
Ending。