11

I have the issue installing a memcached's module for php 7.1. I use MacOS High Sierra and php@7.1 installing using homebrew. During the installation of memcached module for php using command

pecl install memcached

I received the errors:

checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir= to specify the prefix where ZLIB headers and library are located ERROR: `/private/tmp/pear/install/memcached/configure --with-php-config=/usr/local/opt/php@7.1/bin/php-config --with-libmemcached-dir' failed

But I have installed zlib. I can't find a way how to install memcached module after the changes in homebrew repository.

alexius
  • 111
  • 1
  • 1
  • 7

3 Answers3

43
  1. pecl bundle memcached
  2. Change to the directory it output
  3. phpize
  4. Make sure libmemcached and zlib are installed (brew install libmemcached zlib)
  5. Get the zlib directory (brew list zlib)
  6. ./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11/ (replace the zlib path with the one from the previous command)
  7. make
  8. make install
  9. Add the extension line in your php.ini file (ex. change the paths to match what make install output. I added this to my /usr/local/etc/php/7.4/conf.d directory in a file called ext-memcached.ini

[memcached] extension=memcached.so

  1. Verify you installed the module php -m should show you memcached in the outputted list
Ryan Matthews
  • 1,043
  • 9
  • 28
  • Thanks! Your answer saved me tonight. – Ihor Vorotnov Nov 30 '18 at 18:52
  • 1
    Thanks! Works as of May 2019 on PHP7.0 – Lashae May 28 '19 at 08:09
  • This continues to work across versions of php, I tested most recently with php 7.3.7. Just make sure to edit your paths accordingly. The php path for 7.3 (I believe whatever the "current" version is) seems to be /usr/local/Cellar/php with the version under that. That will be where your extension path is set to in step 8. – Ryan Matthews Jul 18 '19 at 19:43
  • 1
    To find your php conf.d file, just `php -i | grep php.ini` and use the first path.Mine was `/usr/local/etc/php/7.3` and cd into conf.d – Philipp Mochine Oct 22 '19 at 15:10
  • Somehow my phpinfo(); did not want to update to memcached even though php -m worked, so I tried this [tutoral](https://grrr.tech/posts/installing-homebrew-php-extensions-with-pecl/) and uninstalled everything. Works perfect now – Philipp Mochine Oct 22 '19 at 19:48
  • I get `make: *** No targets specified and no makefile found. Stop.`. I am dying. – Abana Clara Nov 05 '19 at 07:51
  • 3
    After make install you can just use: extension=memcached.so instead of specyfing full path. – Konrad Gałęzowski Nov 07 '19 at 08:26
  • 1
    Thanks so much, this still works in 2021 on M1 Apple Silicon / Big Sur. For me, the `Cellar` directory was in `/opt/homebrew/` and the `conf.d` directory is in`/opt/homebrew/etc/php/7.4/`. – 0Seven Sep 07 '21 at 00:54
7

You can use env variable PHP_ZLIB_DIR to tell it where zlib is.

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

Full installation.

brew install zlib
yes no | PHP_ZLIB_DIR=$(brew --prefix zlib) pecl install memcached
Kamil Dziedzic
  • 4,721
  • 2
  • 31
  • 47
1

To install memcached prerequisite

  • Install pkg-config and zlib using brew install pkg-config zlib
  • Check Php Version for which you installing should be linked. php -v tells you which php version is active for cli.
  • pecl config-get ext_dir will tell you which version configuration files are set.
  • Get configuration path for zlib that is required while installing brew list zlib Install using sudo pecl install memcached While installing it will ask zlib directory [no] : in that paste zlib configuration path /opt/homebrew/Cellar/zlib/1.2.11 example zlib directory [no] : /opt/homebrew/Cellar/zlib/1.2.11

Restart your php and nginx/apache2 brew services restart php@7.2 brew services restart nginx brew services restart apache2

You can check extension is installed or not by using php -m.

Note : Am using MacPro M1 silicon chip notebook. Installed using homebrew. struggle a lot to fix this issue.

Vijay Sharma
  • 833
  • 8
  • 15