Install Memcache on MAMP PRO 3.5.2 for PHP 5.3.29 in MAC OS Sierra Version 10.12.6

In order to install Memcache, you should install memcached first.

Before all, make sure that you have Xcode Command Line Tools by writing

xcode-select — install

Then install memcached

brew install memcached

This is going to also install the dependencies like openssl and libevent.

After installing memcached, now we can install memcache. But wait, every instruction says that you must have pecl in order to install memcache. However, there is no need to mess with the installation of pecl since it comes in /Applications/MAMP/bin/php/php<your_version>/bin/. You can use it.

Before continue, we need source codes of php in order to compile memcache. Download the appropriate version which you are using already from here: http://php.net/downloads.php

Extract the sources into the directory: /Applications/MAMP/bin/php/php<your_version>/include/php/

Create folders include and php under it if they do not exist. Then run this:

/Applications/MAMP/bin/php/php<your_version>/include/php/configure

Now, let’s install memcache

/Applications/MAMP/bin/php/php<your_version>/bin/pecl i memcache

But, wait! It can come up with an error like this:

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
ERROR: `phpize’ failed

You should install autoconf to resolve this issue.

brew install autoconf

Now, rerun the command:

/Applications/MAMP/bin/php/php<your_version>/bin/pecl i memcache

Now wtf!? It can come up with an error like this:

/Applications/MAMP/bin/php/php<your_version>/include/php/Zend/zend.h:51:11: fatal error: ‘zend_config.h’ file not found

But didn’t we add the source codes? Yes. So what? Sources does not include these folders: TSRM, Zend, ext, main, sapi. Where do we find all of these? No worry, they reside in /usr/include/php already. Copy all of them into /Applications/MAMP/bin/php/php<your_version>/include/php/.

Now, rerun the command:

/Applications/MAMP/bin/php/php<your_version>/bin/pecl i memcache

Finally, it is going to create THE memcache.so file. It will show you on terminal where the file is created.

Now, open MAMP PRO. From the menu bar, go to

File->Edit Template->PHP->PHP <your_version> php.ini

Place this line into opened php.ini file where other extension settings reside

extension=memcache.so

You are done!

PS: This is for only specified PHP version. If you decide to change your PHP version, you should also create a “memcache.so” file for that version separately.