Installing the PHP "memcached" Extension
source link: https://donatstudios.com/OS-X-Mavericks-Memcached-PHP-Extension-Installation
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Installing the PHP "memcached" Extension
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.
System Integrity Protection
If you are running OS X El Capitan or newer you will need to disable System Integrity Protection to modify system files and directories.
To disable System Integrity Protection, boot into recovery mode by restarting and then holding ⌘R
as you hear the startup chime. Then start the Terminal from the Utilities menu.
Run the following command
$ csrutil disable
Then reboot. You are good to go.
If you wish to turn it back on, follow the instructions above but instead use:
$ csrutil enable
Click here for a full post on the topic.
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 Oct. 30, 2013
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 Oct. 30, 2013
The terminal will complain it cannot find the path for libmemcached lib.
Didn't you meet this error?
Comment by: marvin on Oct. 31, 2013
make: *** [memcached.la] Error 1
I am getting this error on 'make'
Comment by: jv on Nov. 2, 2013
brew install autoconf
brew install Libmemcached
then phpize etc.
Comment by: jv on Nov. 2, 2013
add the following line at the end:
typedef const struct memcached_server_st *memcached_server_instance_st;
Comment by: Jared on Nov. 8, 2013
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 Nov. 8, 2013
Comment by: will on Feb. 12, 2014
Comment by: Colin on Feb. 24, 2014
Comment by: Sid on Mar. 5, 2014
Comment by: Valentin on Mar. 20, 2014
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 Aug. 31, 2014
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 Sep. 2, 2014
Comment by: follower on Sep. 2, 2014
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 Oct. 18, 2014
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 Nov. 11, 2014
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 Nov. 11, 2014
Comment by: MintyStark on Nov. 17, 2014
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 Mar. 6, 2015
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: prabhat on Oct. 2, 2015
Please help
Comment by: Jesse G. Donat on Oct. 2, 2015
Not sure exactly what you're asking, but I have a hunch that you might not be running the OS X built in PHP?
If you run
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: prabhat on Oct. 2, 2015
This command helped
pecl install memcache
Comment by: Ansuraj on Jan. 27, 2016
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 Feb. 1, 2016
You should actually not be following these directions and instead just install the extension with brew.
Comment by: olidev on May. 11, 2017
Comment by: Charlotte on Aug. 24, 2017
I got this error:
./php_memcached.h:23:10: fatal error: 'Zend/zend_smart_str.h' file not found
Any idea on how to fix this? Thanks!
Comment by: Andi on Sep. 20, 2017
pecl download memcached-2.1.0 works
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK