How to enable the memcached PHP extension after installing with homebrew?

100,140

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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

Solution 5

First, install memcached library with:

sudo pecl install memcached

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

extension = memcached.so

That's it.

Share:
100,140
MacMac
Author by

MacMac

:-)

Updated on July 07, 2021

Comments

  • MacMac
    MacMac almost 3 years

    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

  • MacMac
    MacMac over 12 years
    I don't know how to give you more information, check my edit.
  • hakre
    hakre over 12 years
    Have you installed php with homebrew as well? And is the .so file inside the directory PHP expects it to be?
  • MacMac
    MacMac over 12 years
    No, I'm using the PHP that came with Lion OS X by default. There is no memcached.so in the directory.
  • MacMac
    MacMac over 12 years
    There is actually no memcached.so around my MacBook, I tried searching with the find command and didn't find it at all.
  • hakre
    hakre over 12 years
    Then first install the memcache PHP extension (next to the server). Without the actual binary of the extension, it's obvious, that it does not work, isn't it?
  • MacMac
    MacMac over 12 years
    Hmm. I fixed the problem, I first installed libmemcached via homebrew then installed memcached with pecl.
  • Brendon Muir
    Brendon Muir about 12 years
    This answers your question better. You think you've installed the php extension for memcached but have only installed memcached itself.
  • yegor256
    yegor256 almost 12 years
    brew install memcached-php gives Error: No available formula for memcached-php
  • Evan
    Evan over 11 years
    what is the correct version of xcode needed for this? will it work with 3.2.6?
  • Brian Noah
    Brian Noah over 11 years
    Installed and got error about autoconf. Next person who reads this, install autoconf by using brew install autoconf
  • JordanC
    JordanC about 11 years
    Try: brew install php54-memcached (or php53 if you are on 5.3)
  • geoidesic
    geoidesic over 10 years
    And how would you "recompile your memcache PHP module" then?
  • msanford
    msanford over 10 years
    Tap: brew tap homebrew/dupes;brew tap josegonzalez/homebrew-php (see github.com/josegonzalez/homebrew-php ) then brew install php55-memcached (or whatever version you're using).
  • Dave Kiss
    Dave Kiss over 9 years
    This was what I was missing: brew install php55-memcached
  • Dave Kiss
    Dave Kiss over 9 years
    brew reinstall memcached
  • henrijs
    henrijs over 9 years
    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.
  • phpguru
    phpguru over 8 years
    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.
  • user269867
    user269867 about 7 years
    what is autoconf?
  • user269867
    user269867 about 7 years
    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.
  • jmontross
    jmontross over 6 years