How to install memcache.so/memcached.so for MAMP Pro (Mac)

Install memcache.so for PHP 5.6

 

1. Install memcached

$ brew install memcached

2. Download php source code

http://www.php.net/downloads.php

 

3. Copy source code to the folder /Applications/MAMP/bin/php/{php version}/include/php

e.g.) /Applications/MAMP/bin/php/php5.6.10/include/php

 

4. Install libiconv

$ brew install homebrew/dupes/libiconv

 

5. Execute configure in php source folder

$ cd /Applications/MAMP/bin/php/php5.6.10/include/php
$ ./configure --with-iconv=/usr/local/Cellar/libiconv/1.14/

 

6. Install zlib

$ brew install zlib

 

7. Create link file for zlib

$ ln -s /usr/local/Cellar/zlib/1.2.8/include/* /usr/local/include    
$ ln -s /usr/local/Cellar/zlib/1.2.8/lib/* /usr/local/lib

 

8. Use pecl to install memcache

$ /Applications/MAMP/bin/php/php5.6.10/bin/pecl install memcache

 

9. Go to MAMP Pro -> File -> Edit Template -> PHP -> PHP 5.6.10

Add following lines to end of file

[memcache]
extension=memcache.so

 

10. Restart services in MAMP

 

Install memcache.so for PHP 7.0

 

1. Re-install pkg-config (if get pkg-config error)

$ brew reinstall pkg-config

 

2. Download php.memcached and create memcache.so

$ cd /Applications/MAMP/bin/php/php7.0.8/include/php/ext
$ wget http://pecl.php.net/get/memcache-3.0.8.tgz
$ tar xf memcache-3.0.8.tgz
$ cd memcache-3.0.8
$ /Applications/MAMP/bin/php/php7.0.8/bin/phpize

9. Go to MAMP Pro -> File -> Edit Template -> PHP -> PHP 5.7.08

Add following lines to end of file

[memcache]
extension=memcached.so

Note:

To use cache memcache in Yii2 + PHP7+, then set cache configuration as below:

<?php
$config = [
    ...
    'components' => [
        'cache' => [
            'class' => 'yii\caching\MemCache',        // Use this to use memcache
            'useMemcached'  =>  true,
            'servers' => [
                [
                    'host' => '127.0.0.1',
                    'port' => 11211,
                    'weight' => 100,
                ],
            ],
        ],
	],
	...
];

 

 

Reference: