如何安装内存缓存扩展(php72,macos Catalina)

How to install memcache extension (php72, macos Catalina)

我无法在 MacOs Catalina 上安装 memcache(不是 memcached)扩展,php 7.2

checking for the location of zlib... configure: error: memcache support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located
ERROR: `/private/tmp/pear/temp/memcache/configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config --enable-memcache-session=yes' failed

我试试

pecl install memcache --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include/zlib.h

但是

Attempting to discover channel "--with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include"...
Attempting fallback to https instead of http on channel "--with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include"...
unknown channel "--with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include" in "--with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include/zlib.h"
invalid package name/package file "--with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/include/zlib.h"

你很接近...你的路径不应该是头文件,而是目录。此外,pecl install 不会将脚本中的命令行参数传递给 ./configure 命令,因此您必须自己执行此操作:

pecl download memcache
open memcache-4.0.5.2.tgz  
cd memcache-4.0.5.2/memcache-4.0.5.2
phpize
./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11
make
sudo make install

您可以使用环境变量 PHP_ZLIB_DIR 告诉它 zlib 在哪里。

PHP_ZLIB_DIR=/usr/local/opt/zlib pecl install memcache