I had to install memcached on Mac OSX El Captain and MAMP and it was quite tricky. Let’s do it together to make your life more easier.
The easiest way is to use
homebrew to install it. If you do not have
brew already, run command in your terminal.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1. Install memcached
memcached, run this command in your terminal.
brew install memcached
Most of the time, everything goes well and that’s the reason why a lot of articles finishes here. I had an issue yesterday with
libevent package. But I have removed and install it again and the issue was solved.
brew remove --force libevent
brew install libevent
2. Install memcached as PHP extension
This quite depends on the PHP version you are using with the MAMP. To find all the supported php memcached version, run this command in the terminal:
brew search memcached
I use PHP 7.0 on localhost, so I have to install
php70-memcached. But as I said, this depends on the PHP version, you are running on localhost.
brew install homebrew/php/php70-memcached
For some reason I was force to run this command, so maybe you will need to run it as well. But it’s also part of the message / help written in terminal, so it’s good idea to read them 😉
brew install --HEAD homebrew/php/php70-memcached
Btw, this command takes a while to finish, but now we should have memcached installed on Mac OS X.
php -i | grep memcached
memcached support => enabled
memcached.compression_factor => 1.3 => 1.3
memcached.compression_threshold => 2000 => 2000
memcached.compression_type => fastlz => fastlz
memcached.serializer => php => php
3. Create memcached.so and update php.ini
Now the memcached is installed for our PHP Cli version (command line version of PHP), but it might not be accessible for PHP running in browser. If you didn’t know there’re 2 version of PHP, it’s fine ;). You learned another new thing.
3a. Download memcached.so from Github
I found a lot of articles describing how to build
memcached.so from source codes of PHP, but actually it never worked for me. Most probably I was doing some silly mistakes, but at the end, I found Github repository with already done
memcached.so files which are ready to be downloaded and used.
I would recommend you to do the same – download it and use it. It will save you a lot of time 😉
3b. Copy memcached.so to proper extension folder
As I said earlier, I use PHP 7.0 on my localhost, so the folder with extension for me is
So move the file to the proper folder.
3c. Edit php.ini and add info about new extension to be loaded
Somewhere in this file. It’s good idea to find where
extension= are and add it as the last one.
3c. Restart MAMP
The last thing to be done is to restart MAMP and check whether everything is working as expected.
If you run
http://localhost:8888/MAMP/index.php?language=English&page=phpinfo in your browser, you should find
memcached section on this page. If yes, congratulation – memcached is installed on your MAMP and you can take advantage of it.
I do not know better feeling than when the things are finally working as expected. So CONGRATULATION, memcached is up and running on our Mac OS X El Captain and also in MAMP.
Please let me know if you had any other issues while installing mamcached on your Mac OS X using MAMP, so we can solve them together.