12

I'm having trouble installing the "memcached" PHP extension from PECL, though I can successfully installed the "memcache" extension. (They are separate PHP extensions.)

For example, these commands work okay:

$ sudo pecl install memcache
$ sudo pecl install APC
$ sudo pecl install oauth

However, attempting to install memcached causes errors:

$ sudo pecl install memcached
...
ld: library not found for -lmemcached
collect2: ld returned 1 exit status
make: *** [memcached.la] Error 1
ERROR: `make' failed

I'm using pecl, memcached, and libmemcached from Mac Ports (macports.org) on a recent Intel Mac. The libmemcached libraries can be found in /opt/local:

/opt/local/include/libmemcached
/opt/local/include/libmemcached/libmemcached_config.h
/opt/local/lib/libmemcached.2.0.0.dylib
/opt/local/lib/libmemcached.2.dylib
/opt/local/lib/libmemcached.a
/opt/local/lib/libmemcached.dylib
/opt/local/lib/libmemcached.la

Any idea what I may be doing wrong?

richardkmiller
  • 2,902
  • 3
  • 31
  • 29

4 Answers4

34

Andrei Zmievski (developer of the memcached plugin) kindly answered my email request with the following instructions:

$ pecl download memcached
$ tar zxvf memcached-1.0.0.tgz (or whatever version downloads)
$ cd memcached-1.0.0
$ phpize
$ ./configure --with-libmemcached-dir=/opt/local
$ make
$ sudo make install

This worked perfectly.

richardkmiller
  • 2,902
  • 3
  • 31
  • 29
  • 3
    What is /opt/local a reference to? I don't understand this part. – Chris Harrison Mar 23 '12 at 05:01
  • For memcache (and not memcached) with MAMP 1.9 i had to use this way to configure: `./configure --prefix=/Applications/MAMP/ --with-php-config=/Applications/MAMP/bin/php5.3/bin/php-config` – phemios Apr 05 '12 at 15:50
  • 1
    @ChrisHarrison: /opt/local is the location of MacPorts (though I'm now using Brew.) – richardkmiller May 05 '12 at 17:09
  • Man, the hoops you need to go through. Anyway, the above solution worked for me (using libmemcached 1.0.10 and memcached 2.1.0), with some additional steps: doing a "sudo port install libmemcached" first, and then adding "extensions=memcached.so" to my /private/etc/php.ini and doing a "sudo apachectl restart" for good measure. – PapaFreud Nov 08 '12 at 09:40
  • 1
    make: *** No rule to make target `install'. Stop. –  Jun 11 '18 at 03:12
2

same situation here. i had to do the above, but with explicit path names (i run my php etc. out of /opt/local)

  • /opt/local/bin/pecl download memcached
  • tar zxvf memcached-1.0.0.tgz
  • cd memcached-1.0.0
  • /opt/local/bin/phpize
  • ./configure --prefix=/opt/local --with-php-config=/opt/local/bin/php-config --with-libmemcached-dir=/opt/local
  • make
  • make install

normally this kind of stuff is pretty simple on os x with macports, but there is no php5-memcached package yet (only one for the older, memcache (no "d") package). oh, an i also had to install an older version of libmemcached, since the latest version didn't compile on os x 10.5.8 for me. oy!

Paul
  • 739
  • 5
  • 11
  • For others, I was able to use this for 'memcache' (not memcache*d*) for PHP 8.0 on a Mac still running Catalina (10.15.7) over a decade later. I don't have /opt/local/bin/ but you can compile it wherever you like, e.g. /usr/local/src/ and it will automatically put it in a directory such as /usr/local/Cellar/php@8.0/8.0.23_1/pecl/20200930/ – William Turrell Sep 29 '22 at 14:13
1

As you've seen, the new memcached extension, uses libmemcached to do the heavy lifting. If it were Linux, I'd say that it was possible that you don't have /opt/local/lib/ listed in ld.so.conf (and run 'ldconfig').

MaxOSX doesn't use that though. It is, however installable from 'ports' apparently. http://lsimons.wordpress.com/2008/05/01/serious-php-part-1/

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
0

Well, after many tries only this solution works for me.

  1. Install XAMPP
  2. Install brew (https://github.com/Homebrew/homebrew/wiki/Installation)
  3. $ brew
  4. install libmemcached
  5. cd /Applications/XAMPP/xamppfiles/bin/
  6. $ sudo ./pecl install memcached

Build process completed successfully Installing '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/memcached.so' install ok: channel://pecl.php.net/memcached-2.2.0 configuration option "php_ini" is not set to php.ini location You should add "extension=memcached.so" to php.ini

VOILA !!