skip to Main Content

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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search