Class 'ZipArchive' not found MAC

MAC 系统升级到 10.15.1 后,PHP扩展环境失效。报错 Class 'ZipArchive' not found


1 安装 pecl

1)执行  pecl version

报错:  pecl: command not found

2) 安装  pecl

1)curl -O https://pear.php.net/go-pear.phar

2)sudo php -d detect_unicode=0 go-pear.phar

3)输入: 1

4)输入: 4

5)回车 (可能多次回车)

3) 执行 pecl version

返回如下:

PEAR Version: 1.10.9

PHP Version: 7.3.9

Zend Engine Version: 3.3.9

Running on: Darwin jiaweideMacBook-Pro.local 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64

2 安装zip

1) pecl search zip

2) sudo pecl install zip

downloading zip-1.15.5.tgz ...Starting to download zip-1.15.5.tgz (286,794 bytes)............................................................done: 286,794 bytes14 source files, buildingrunning: phpizeConfiguring for:PHP Api Version:        20180731Zend Module Api No:      20180731Zend Extension Api No:  320180731Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.ERROR: `phpize' failed如果 失败 按照提示 安装 autoconf

3) brew install autoconf

4) sudo pecl install zip

downloading zip-1.15.5.tgz ...

Starting to download zip-1.15.5.tgz (286,794 bytes)

............................................................done: 286,794 bytes

14 source files, building

running: phpize

Configuring for:

PHP Api Version:        20180731

Zend Module Api No:      20180731

Zend Extension Api No:  320180731

building in /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5

running: /private/tmp/pear/install/zip/configure --with-php-config=/usr/bin/php-config

checking for grep that handles long lines and -e... /usr/bin/grep

checking for egrep... /usr/bin/grep -E

checking for a sed that does not truncate output... /usr/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-apple-darwin19.0.0

checking host system type... x86_64-apple-darwin19.0.0

checking target system type... x86_64-apple-darwin19.0.0

checking for PHP prefix... /usr

checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib

checking for PHP extension directory... /usr/lib/php/extensions/no-debug-non-zts-20180731

checking for PHP installed headers prefix... /usr/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... no

checking for nawk... no

checking for awk... awk

checking if awk is broken... no

checking for zip archive read/writesupport... yes, shared

checking libzip... yes

checking PHP version... 7.3

checking for pkg-config... /usr/local/bin/pkg-config

checking for libzip... from pkgconfig: version 1.5.2 found in /usr/local/Cellar/libzip/1.5.2/lib

checking for zip_open in -lzip... yes

checking for zip_file_set_encryption in -lzip... yes

checking for zip_libzip_version in -lzip... yes

checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld

checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no

checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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 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 dlfcn.h usability... yes

checking dlfcn.h presence... yes

checking for dlfcn.h... yes

checking the maximum length of command line arguments... 196608

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 for dsymutil... dsymutil

checking for nmedit... nmedit

checking for -single_module linker flag... yes

checking for -exported_symbols_list linker flag... yes

checking if cc supports -fno-rtti -fno-exceptions... yes

checking for cc option to produce PIC... -fno-common

checking if cc PIC flag -fno-common works... yes

checking if cc static flag -static works... no

checking if cc supports -c -o file.o... yes

checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes

checking dynamic linker characteristics... darwin19.0.0 dyld

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

running: make

/bin/sh /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/libtool --mode=compile cc -I/usr/local/Cellar/libzip/1.5.2/include -I. -I/private/tmp/pear/install/zip -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/include -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/main -I/private/tmp/pear/install/zip -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/install/zip/php73  -DHAVE_CONFIG_H  -g -O2  -c /private/tmp/pear/install/zip/php73/php_zip.c -o php73/php_zip.lo

mkdir php73/.libs

cc -I/usr/local/Cellar/libzip/1.5.2/include -I. -I/private/tmp/pear/install/zip -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/include -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/main -I/private/tmp/pear/install/zip -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/install/zip/php73 -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/install/zip/php73/php_zip.c  -fno-common -DPIC -o php73/.libs/php_zip.o

/bin/sh /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/libtool --mode=compile cc -I/usr/local/Cellar/libzip/1.5.2/include -I. -I/private/tmp/pear/install/zip -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/include -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/main -I/private/tmp/pear/install/zip -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/install/zip/php73  -DHAVE_CONFIG_H  -g -O2  -c /private/tmp/pear/install/zip/php73/zip_stream.c -o php73/zip_stream.lo

cc -I/usr/local/Cellar/libzip/1.5.2/include -I. -I/private/tmp/pear/install/zip -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/include -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/main -I/private/tmp/pear/install/zip -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/install/zip/php73 -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/install/zip/php73/zip_stream.c  -fno-common -DPIC -o php73/.libs/zip_stream.o

/bin/sh /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/libtool --mode=link cc -DPHP_ATOM_INC -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/include -I/private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/main -I/private/tmp/pear/install/zip -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/private/tmp/pear/install/zip/php73  -DHAVE_CONFIG_H  -g -O2    -o zip.la -export-dynamic -avoid-version -prefer-pic -module -rpath /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/modules  php73/php_zip.lo php73/zip_stream.lo -Wl,-rpath,/usr/local/Cellar/libzip/1.5.2/lib -L/usr/local/Cellar/libzip/1.5.2/lib -lzip

mkdir .libs

cc ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/zip.so -bundle  php73/.libs/php_zip.o php73/.libs/zip_stream.o  -L/usr/local/Cellar/libzip/1.5.2/lib -lzip  -Wl,-rpath -Wl,/usr/local/Cellar/libzip/1.5.2/lib

dsymutil .libs/zip.so || :

creating zip.la

(cd .libs && rm -f zip.la && ln -s ../zip.la zip.la)

/bin/sh /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/libtool --mode=install cp ./zip.la /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/modules

cp ./.libs/zip.so /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/modules/zip.so

cp ./.libs/zip.lai /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/modules/zip.la

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

Libraries have been installed in:

  /private/tmp/pear/install/pear-build-rootTVh4R1/zip-1.15.5/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 `DYLD_LIBRARY_PATH' environment variable

    during execution

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'.

running: make INSTALL_ROOT="/private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5" install

Installing shared extensions:    /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib/php/extensions/no-debug-non-zts-20180731/

running: find "/private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5" | xargs ls -dils

8609468174  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5

8609468575  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr

8609468576  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib

8609468577  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib/php

8609468578  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib/php/extensions

8609468579  0 drwxr-xr-x  3 root  wheel    96 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib/php/extensions/no-debug-non-zts-20180731

8609468580 144 -rwxr-xr-x  1 root  wheel  70860 11 16 08:49 /private/tmp/pear/install/pear-build-rootTVh4R1/install-zip-1.15.5/usr/lib/php/extensions/no-debug-non-zts-20180731/zip.so

Build process completed successfully

Installing '/usr/lib/php/extensions/no-debug-non-zts-20180731/zip.so'

install ok: channel://pecl.php.net/zip-1.15.5

configuration option "php_ini" is not set to php.ini location

You should add "extension=zip.so" to php.ini

3 配置 php.ini

0) vi /private/etc/php.ini

如果报错,执行下面的操作(因为mac 本身 在/private/etc/没有 php.ini ,可以 拷贝 /private/etc/php.ini.default  )

1) sudo cp /private/etc/php.ini.default /private/etc/php.ini

2) cd /private/etc/

3) chmod o+w php.ini

4) vi php.ini

5) Shit+G 进入文件末尾, 输入:i 进入编辑模式

6) 拷贝 extension=zip.so;

7) :wq

4 执行 php -m 查看扩展



补充:

1)忘了可能哪一步会报错, zlib 版本过低, 如果报错,执行 brew zlib

2) brew 建议 update 一次,可能需要1-2个小时,建议升级。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容