Installing the PHP "memcached" Extension
- Comments:
- 27
Please Note
This tutorial only covers the default PHP installation that ships with Mac OS X / macOS. If you have installed a new installation this does not cover you.
For those using brew, you can simply brew install
the appropriate brew formula for the extension.
These directions are verified to work with Mac OS X 10.9 Mavericks through macOS 10.14 Mojave.
The first step is to install the latest version of Xcode. On modern versions of MacOS this can be done from the App Store.
After this, install the Xcode developer tools.
$ xcode-select --install
Special note to Mojave users if the following steps fail, you may need to reinstall your Xcode header files. Instructions for that can be found here.
Next we will need to install the required dependencies before we can build the extension. If you are not already using Homebrew you should be.
$ brew install wget autoconf pkg-config libmemcached
You will also want to make sure you have PEAR installed; full instructions can be found here but can be summarized as follows:
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
Then in the /tmp
directory we will create a folder we can work in.
$ cd /tmp
$ mkdir memcached-work
$ cd memcached-work
Next we will use pecl, part of pear, to fetch the current version of the extension.
The version of the memcached extension will vary so you will need to update the paths accordingly.
$ pecl download memcached
$ open memcached-{{version}}.tgz
$ cd memcached-{{version}}/memcached-{{version}}
$ phpize
$ ./configure
$ make
$ sudo make install
Finally you will need to add the following line to your php.ini
extension = memcached.so
You can verify your installation with the following:
$ php --info | grep memcached\\.
Depending on your setup now you may want to restart apache.
$ sudo apachectl restart
You should be all set to go!
Comment by: liangyu on
as to the command --phpize, users may meet this problem like "Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script."
-- brew install autoconf
can fix this problem
Comment by: liangyu on
The terminal will complain it cannot find the path for libmemcached lib.
Didn't you meet this error?
Comment by: marvin on
make: *** [memcached.la] Error 1
I am getting this error on 'make'
Comment by: jv on
add the following line at the end:
typedef const struct memcached_server_st *memcached_server_instance_st;
Comment by: Jared on
Thanks for the guide. I followed your guide and was successful on building memcahce on my localhost. However when I try to connect to a remote memcache server it crashes with the following error...any ideas?
donedyld: lazy symbol binding failed: Symbol not found: _mmc_queue_free
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20100525/memcache.so
Expected in: flat namespace
dyld: Symbol not found: _mmc_queue_free
Referenced from: /usr/lib/php/extensions/no-debug-non-zts-20100525/memcache.so
Expected in: flat namespace
Comment by: Jared on
Comment by: will on
Comment by: Colin on
Comment by: Valentin on
xcode-select --install
brew install autoconf
brew install Libmemcached
cd /tmp
mkdir memcached-work
cd memcached-work
pecl download memcached
open memcached-2.1.0.tgz
cd memcached-2.1.0/memcached-2.1.0
phpize
./configure
make
sudo make install
Then add extension = memcached.so to php.ini.
to find which php.ini you're using run in console:
php --ini
Don't forget to restart apache:
sudo apachectl -k restart
Comment by: follower on
I've done all this steps, restarted Apache.
php --ini says 'memcached support => enabled', etc. (too many lines).
But I still get error "Fatal error: Class 'Memcached' not found in ..."
What should I check?
Comment by: Jesse G. Donat on
Comment by: follower on
Of course I tried rebooting.
How can I check if nothing disabling it?
PHP config has included memcached extension ('/etc/php.ini' path is displaying in phpinfo() output)
Comment by: JB Manos on
xcode-select --install
then, run the PEAR installer on the built-in: sudo php -d detect_unicode=0 /usr/lib/php/install-pear-nozlib.phar
upgrade PEAR: sudo pear upgrade
then PECL: sudo pecl install -f ... (in this case, memcached)
The benefit to using this method is that you'll get a system-wide pear installation for the native PHP. Cheers!
Comment by: Rob Colburn on
brew install php55-memcached
(replace with your version of brew php formulae)
http://braumeister.org/repos/josegonzalez/homebrew-php/formula/php55-memcached
Comment by: Jesse G. Donat on
Comment by: MintyStark on
I think I got it 99% of the way there.
I installed it with my AMPPS PHP
/Applications/AMPPS/php-5.3/bin/phpize CFLAGS='-arch i386'
CFLAGS='-arch i386' ./configure --with-php-config=/Applications/AMPPS/php-5.3/bin/php-config
make
sudo make install
Everything installed ok.
PHP is showing class_exists('Memcached') as true, but Memcached is not displayed in phpinfo(). Also I get a crash when connecting to it.
Also my apache error log shows:
dyld: Symbol not found: _memcached_create
Referenced from: /Applications/AMPPS/php-5.3/lib/extensions/ext/memcached.so
Expected in: flat namespace
[Mon Nov 17 13:50:18.953115 2014] [core:notice] [pid 53238] AH00052: child pid 56107 exit signal Trace/BPT trap (5)
Any Thoughts?
Comment by: Martin on
xcode-select: error: no developer tools were found, and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'.
I however installed from the AppStore - is that ok?
Comment by: Jesse G. Donat on
which phpat the command line you *should* get
/usr/bin/php- if you get something else you've installed a secondary copy of PHP. These directions will only work with OS X's built in copy of PHP I'm afraid.
Comment by: Ansuraj on
Even after following the above steps, I was unable to use memcached in my project, neither was I able to see it in phpinfo(). It was because memcached and php5-memcached extension was installed via cli.
I had to do the following:
sudo cp /usr/local/Cellar/php55/5.5.30/lib/php/extensions/no-debug-non-zts-20121212/memcache.so /usr/lib/php/extensions/no-debug-non-zts-20121212/memcache.so
sudo cp /usr/local/Cellar/php55/5.5.30/lib/php/extensions/no-debug-non-zts-20121212/memcached.so /usr/lib/php/extensions/no-debug-non-zts-20121212/memcached.so
Please change the above commands to suit your php-version paths.
Comment by: Jesse G. Donat on
You should actually not be following these directions and instead just install the extension with brew.