35

I recently installed memcached with homebrew, I'm not entirely sure how to enable it on my PHP envirionment since I added extension=memcached.so in /etc/php.ini in Lion OS X.

Even I restarted apache too, nothing is still loaded.

If I call get_loaded_extensions(), I do not see memcached in the list, how can I enable it when installed from homebrew?

EDIT:

What I did in Terminal was:

$ brew install memcached

It installed just fine, now I went to /etc/php.ini and appended:

extension=memcached.so

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
MacMac
  • 34,294
  • 55
  • 151
  • 222
  • 1
    What does your PHP error log state about the `extension` command you have given? – hakre Oct 22 '11 at 15:40
  • 1
    There's no extension command. I can see in my error log: `PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so'` – MacMac Oct 22 '11 at 15:44
  • That's the explanation: PHP is unable to load the library file you've provided. Can be that the file does not exists, can be that the file is just not compatible. – hakre Oct 22 '11 at 15:52
  • But the reason I'm asking, is to how to make the installed memcached work with PHP? – MacMac Oct 22 '11 at 16:00
  • See my answer. If you can provide more information, more information can be given. But as long as you don't, it's not possible at all. I don't know what you did, so it's necessary to stick to the factual information you can provide. For example the error message, see my answer. – hakre Oct 22 '11 at 16:04
  • It's worth noting for others that find this, at least at the moment, the memcached pecl module won't compile for php 5.4 or 5.5. Readers in the future: check the status of this ticket https://bugs.php.net/bug.php?id=65134 – msanford Aug 18 '13 at 01:20

7 Answers7

45

Install Memcached:

# lists all memcached related packages
brew search memcached

# install memcached as well as memcached extension for PHP
brew install memcached
brew install php54-memcached

# start memcached daemon with 24MB on port 11211 (default)
memcached -d -m 24 -p 11211

Add to your php.ini file to add:

extension=memcached.so

Restart php or php5-fpm and your server. Verify:

php -i | grep memcached
# should show memcached version, etc.
aleemb
  • 31,265
  • 19
  • 98
  • 114
  • 1
    This was what I was missing: `brew install php55-memcached` – Dave Kiss Dec 03 '14 at 22:21
  • 1
    It now seems as adding "extension=memcached.so" is not needed as php on startup says "Additional .ini files parsed => /usr/local/etc/php/5.4/conf.d/ext-memcached.ini" which has that line in it. – henrijs Dec 13 '14 at 06:58
  • 3
    The above installation works for CLI but with Apache it is not working. Any idea how to fix for apache I am trying to add additional ini in apache but not effective either. Any help is much appreciated. – user269867 Apr 27 '17 at 23:00
14

Install:

brew install memcached
OR
sudo pecl install memcached

Add this line to /etc/php.ini:

extension = memcached.so
OR
extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so"

If you are having trouble finding where it lives do

mdfind memcached.so -name
=> /usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so

Make sure it is running as a daemon (-d):

/usr/local/bin/memcached -d

Restart apache:

sudo apachectl restart
jmontross
  • 3,533
  • 1
  • 21
  • 17
12

You'll need to install libmemcached with homebrew, not just memcached. Do this:

brew install libmemcached

Then try recompiling your memcache PHP module. Should be good to go

Eric
  • 121
  • 2
  • 6
    And how would you "recompile your memcache PHP module" then? – geoidesic Aug 12 '13 at 14:40
  • `brew reinstall memcached` – Dave Kiss Dec 03 '14 at 22:22
  • 1
    In fact libmemcached was my issue as well. I had already installed it, so when I tried `brew install libmemcached` brew said Warning: libmemcached-1.0.18_1 already installed, it's just not linked. So I ran brew link libmemcached and then there was a permissions issue on /usr/local/include so I chown -R that folder to my user and then brew link ran fine, and then the extension worked, the error went away and my site loaded just fine. – phpguru Sep 02 '15 at 00:14
11

First, install memcached library with:

sudo pecl install memcached

Then, add this line to /etc/php.ini:

extension = memcached.so

That's it.

yegor256
  • 102,010
  • 123
  • 446
  • 597
10

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20090626/memcached.so'

That's the information PHP is giving you, stick to it.

It's either:

  • The file you have specified does not exists. Check your file-system.
  • The file you've specified can not be read by PHP, check the rights of the file.
  • The file you've specified is incompatible with your PHP binary. Check if you have compiled the right sources and compilation went well.
hakre
  • 193,403
  • 52
  • 435
  • 836
  • I don't know how to give you more information, check my edit. – MacMac Oct 22 '11 at 16:26
  • Have you installed php with homebrew as well? And is the .so file inside the directory PHP expects it to be? – hakre Oct 22 '11 at 16:41
  • No, I'm using the PHP that came with Lion OS X by default. There is no `memcached.so` in the directory. – MacMac Oct 22 '11 at 17:03
  • There is actually *no* `memcached.so` around my MacBook, I tried searching with the `find` command and didn't find it at all. – MacMac Oct 22 '11 at 17:16
  • Then first [install the memcache PHP extension](http://www.php.net/manual/en/memcache.installation.php) (next to the server). Without the actual binary of the extension, it's obvious, that it does not work, isn't it? – hakre Oct 22 '11 at 17:18
  • Hmm. I fixed the problem, I first installed libmemcached via homebrew then installed memcached with pecl. – MacMac Oct 22 '11 at 17:23
4

In Mac OS X El Capitan you can use

brew install homebrew/php/php55-memcached
dsandrade
  • 576
  • 5
  • 9
2

You can install the memcache.so module the following way:

brew install memcached-php

(Note the above is currently broken if you don't have the right Xcode version)

Then go to your php.ini file and add the following (Replace VERSION with the correct value):

extension="/usr/local/Cellar/memcached-php/VERSION/memcached.so"

Then restart apache:

sudo apachectl restart

If you can't figure out which php.ini file is being used, try calling the phpinfo() command. It will tell you exactly which php.ini file it's using.

Saurav
  • 3,096
  • 3
  • 19
  • 12
  • 1
    This answers your question better. You think you've installed the php extension for memcached but have only installed memcached itself. – Brendon Muir Mar 22 '12 at 03:58
  • 3
    `brew install memcached-php` gives `Error: No available formula for memcached-php` – yegor256 Aug 02 '12 at 08:20
  • what is the correct version of xcode needed for this? will it work with 3.2.6? – Evan Sep 06 '12 at 19:45
  • 1
    Try: brew install php54-memcached (or php53 if you are on 5.3) – JordanC Apr 05 '13 at 10:51
  • 2
    Tap: `brew tap homebrew/dupes;brew tap josegonzalez/homebrew-php` (see https://github.com/josegonzalez/homebrew-php ) then `brew install php55-memcached` (or whatever version you're using). – msanford Aug 18 '13 at 01:02