Skip to content

Instantly share code, notes, and snippets.

@ryanjbonnell
Last active March 23, 2023 18:01
Show Gist options
  • Save ryanjbonnell/3880048 to your computer and use it in GitHub Desktop.
Save ryanjbonnell/3880048 to your computer and use it in GitHub Desktop.
Install Memcache on Mac OS X 10.8 "Mountain Lion"
# memcached requires libevent
cd /usr/local/src
curl -L -O http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
tar -xvzf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable*
./configure
make
sudo make install
# Compile memcached utility
cd /usr/local/src
curl -L -O http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
tar -xvzf memcached-1.4.13.tar.gz
cd memcached-1.4.13*
./configure
make
sudo make install
# Create .bash_profile alias to start memcached as needed
alias m="memcached -d -m 24 -p 11211"
# Install autoconfig
cd /usr/local/src
curl -L -O http://gnu.mirrors.hoobly.com/gnu/autoconf/autoconf-2.69.tar.gz
tar xzf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local
make
sudo make install
# Compile and copy memcached.so module
cd /usr/local/src
curl -O http://pecl.php.net/get/memcache-2.2.7.tgz
tar -xvzf memcache-2.2.7.tgz
cd memcache-2.2.7
phpize
./configure --enable-memcache
make
sudo make install
# If using MAMP
# cp modules/memcache.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/
# emacs /Applications/MAMP/bin/php/php5.3.6/conf/php.ini # add line: extension=memcache.so
# If using Apache2
# sudo emacs /etc/php.ini # add line: extension=memcache.so
@akmalfikri
Copy link

I have this error pops out when I do line 3 :
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.

@daveharding
Copy link

Likewise, same problem here. Any solution?

@djungowski
Copy link

It's because the link triggers a redirect which curl obviously is unable to follow:
djungowski$ curl https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
<html><body>You are being <a href="http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz"&gt;redirected&lt;/a&gt;.&lt;/body&gt;&lt;/html>

If you copy-paste the link into your browser it works.

@howanghk
Copy link

it is a HTTP 302 redirect. you should use the -L option so curl will follow the redirect
curl -L -O https://github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz

@joaoneto
Copy link

Thanks!

@matth3wga0
Copy link

Line 33 should be "curl -O http://pecl.php.net/get/memcache-2.2.7.tgz"
Or phpize can't find config.m4

@cawhite78
Copy link

Line 33 corrections

cd /usr/local/src
curl -O http://pecl.php.net/get/memcache-2.2.7.tgz
tar -xvzf memcache-2.2.7.tgz
cd memcache-2.2.7.tgz
phpize
./configure --enable-memcache
make
make install

@pcockwell
Copy link

Lines 25 and 26 should be

tar -xvzf autoconf-2.69.tar.gz
cd autoconf-2.69

Also, @coreywebpt, you need to drop the .tgz on the cd command. It should be

cd memcache-2.2.7

@ryanjbonnell
Copy link
Author

Gist has been updated with all of the above feedback.

@tarunhere
Copy link

Awesome...this script worked like a charm.
still memcache is not working for me, when I write - whereis libevent
it gives no result, does that means that libevent has not been installed!!
gave this error
Memcache::get(): Server localhost (tcp 11211) failed with

I am on MAC OS X 10.8.3 (12D78)

@traday
Copy link

traday commented May 7, 2013

Wouldn't it be easier to just do:
brew install memcached

@msassa
Copy link

msassa commented Jun 19, 2013

Very nice.. this works perfect. Thanks.

@axlotl
Copy link

axlotl commented Jul 9, 2013

@traday: that doesn't install the php extension. Also I think if you do install memcached through homebrew you also need to install libmemcached likewise.

More generally, the manual build of the extension as described here worked for me when pecl didn't. Configure flag I'm guessing. Thanks.

@tinagu
Copy link

tinagu commented Oct 21, 2013

Nice. This works

@gguardin
Copy link

Ops... I get this error at line 16 (make)

gcc -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -o memcached memcached-memcached.o memcached-hash.o memcached-slabs.o memcached-items.o memcached-assoc.o memcached-thread.o memcached-daemon.o memcached-stats.o memcached-util.o memcached-cache.o -levent
clang: error: argument unused during compilation: '-pthread'
make[2]: *** [memcached] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Any ideas?

Thanks

@inspire22
Copy link

Def use homebrew instead

@felipebcs
Copy link

Thanks for this gist!

Just for the record if anyone needs it:

For my XAMPP installation I used the following to compile with the proper PHP binaries for my case:

curl -L -O http://pecl.php.net/get/memcache-2.2.7.tgz
tar -xvzf memcache-2.2.7.tgz
cd memcache-2.2.7
/Applications/XAMPP/xamppfiles/bin/phpize
./configure --enable-memcache --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config
make
sudo make install

(I've installed libevent and memcached using macports and I used this code to compile the .so and add to PHP)

@vivekkodu
Copy link

While running the make step of the memcached i am facing following error:
/Library/Developer/CommandLineTools/usr/bin/make all-recursive
Making all in doc
/Library/Developer/CommandLineTools/usr/bin/make all-am
make[3]: Nothing to be done for `all-am'.
gcc -g -O2 -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -o memcached memcached-memcached.o memcached-hash.o memcached-slabs.o memcached-items.o memcached-assoc.o memcached-thread.o memcached-daemon.o memcached-stats.o memcached-util.o memcached-cache.o -levent
clang: error: argument unused during compilation: '-pthread'
make[2]: *** [memcached] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Any suggestions on how to resolve this??

@ecamaj
Copy link

ecamaj commented Dec 22, 2014

I'm also getting this -pthread error. That makes three of us.

Anyone can help?

@mibalan
Copy link

mibalan commented Mar 30, 2015

@ecamaj actually four :)

@mibalan
Copy link

mibalan commented Mar 30, 2015

Didn't find any solution to this compilation error, but I was able to install it via brew install memcached

@davidlukac
Copy link

I was building memcache 3.0.8 for PHP 5.6 from Acquia DevDesktop and I was getting error about incorrect architecture (also when I installed memcache via brew). The solution was to add "32bit" flags for the configuration script:

./configure --enable-memcache --with-php-config=/Applications/DevDesktop/php5_6/bin/php-config "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"

The error I was getting was something like wrong architecture in Unknown on line 0 in MAMP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment