tinkerr
tinkerr

Reputation: 1058

pecl install memcached - Can't find ZLIB headers under "/opt/homebrew/opt/zlib/include"

I have installed PHP, zlib and memcached using Homebrew on a Mac with Apple silicon. I am trying to install the memcached extension for PHP using

sudo pecl install memcached

When it prompts me for zlib directory [no] : I specified "/opt/homebrew/opt/zlib/include"

I have confirmed that this directory contains the files zlib.h and zconf.h. brew info zlib also tells me

For compilers to find zlib you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/zlib/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/zlib/include"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"

So I seem to be supplying the correct path for zlib. However, running sudo pecl install memcached is throwing the following error:

checking whether to use system FastLZ library... no
checking for ZLIB... yes, shared
checking for pkg-config... /opt/homebrew/bin/pkg-config
configure: error: Can't find ZLIB headers under "/opt/homebrew/opt/zlib/include"
ERROR: `/private/tmp/pear/temp/memcached/configure --with-php-config=/opt/homebrew/opt/php/bin/php-config --with-libmemcached-dir=no --with-zlib-dir=/opt/homebrew/opt/zlib/include --with-system-fastlz=no --enable-memcached-igbinary=no --enable-memcached-msgpack=no --enable-memcached-json=no --enable-memcached-protocol=no --enable-memcached-sasl=no --enable-memcached-session=no' failed

How do I fix this?

Upvotes: 4

Views: 1679

Answers (3)

jamesbtate
jamesbtate

Reputation: 1399

On an old RedHat 7 server I wanted to install the memcached for the rh-php73 SCL module.

First, install PEAR/PECL for PHP 7.3 and the zlib and libmemcached development headers:

sudo yum install rh-php73-php-pear libmemcached-devel zlib-devel

Now use pecl to install the memcached extension:

sudo /opt/rh/rh-php73/root/bin/pecl install memcached

At the first two prompts use /usr/ for the libmemcached directory and for the zlib directory. The path it wants is not the path to the directory containing the headers.

Upvotes: 0

N S
N S

Reputation: 2603

I had the same issue and managed to get it working on Mac using the path:

/opt/homebrew/opt/zlib

NOT "/opt/homebrew/opt/zlib/include" even though that is technically the folder which contains the headers, the error message is misleading.

For me, the --with-zlib-dir= argument did nothing, I had to provide the path when prompted during installation:

pecl install memcached
zlib directory [no] : /opt/homebrew/opt/zlib

Upvotes: 5

FGM
FGM

Reputation: 2860

Could not find how to use the info in the other answers. The environment variables given in the question do not change the result, even when using the accepted answer.

The fix was the one give in ancient PHP issue https://bugs.php.net/bug.php?id=56522 :

PHP_ZLIB_DIR=/opt/homebrew/opt/zlib pecl install memcache

Upvotes: 1

Related Questions