Installing memcache on osx for php

Finally got memcache working!

I am compiling the steps here in case I need to do it again.

First install libevent. This is a dependency to memcached, so need to get it.

cd /tmp
curl -OL https://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

Then install memcached.

# Compile memcached utility
cd /tmp
curl -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

At this point, if everything goes well, the memcache daemon should be ready to run. You can try the following to see if memcached returns anything to you.

memcached -d -m 24 -p 11211
telnet localhost 11211
stats
quit

When you run memcached -d -m 24 -p 11211, you are assigning 24Mb ram for memcache to use, and using the port 11211, which is the default port for memcache. The -d runs memcache as a daemon.

After you run stats, you should see some stats returned on your screen. If so, that means memcache is running fine now.

Next step is to make sure php can talk to memcache.

Download the php extension to memcached from this link: http://pecl.php.net/package/memcache. I recommend getting the stable version, 2.2.6 as of June 2012.

After uncompressing it, do phpize. If you get an error on not having autoconf, install it with brew. See my other tutorial on how to do that.

gzip -d < memcache-2.2.6.tgz | tar -xvf -
cd memcache-2.2.6
phpize

After phpize gives you your php version info, do the usual compile and install:

./configure
make
sudo make install

Double check that the memcache.so file is in your php include directory.

ls /usr/lib/php/extensions/no-debug-non-zts-20090626/

It should be there… if not, you can manually copy the file yourself. It’s located under the “modules” folder.

Now, modify your /etc/php.ini file to include this extension.

extension = memcache.so

Then finally, restart apache.

sudo apachectl restart

If everything goes well, your phpinfo() should give you a section on memcached, indicating memcached is loaded properly.

Congratulation! At this point php is ready to interact with memcache. But just how to do that in code? Let’s wait for my part 2 of this tutorial. 😉

Ref link:
http://readystate4.com/2012/03/15/installing-memcached-on-os-x-10-7-3-lion-on-mamp/
http://www.glenscott.co.uk/blog/2009/08/30/install-memcached-php-extension-on-os-x-snow-leopard/
http://jamiecurle.co.uk/blog/memcached-on-osx-without-macports/

8 thoughts on “Installing memcache on osx for php

  1. Rich says:

    Hello Brian,
    On and off in the past two days, I was searching for a solution to install memcache to XAMPP, after googling many related posts, yours is the clearest I came across, I finally got memcache to work on XAMPP! Thanks for your help. 🙂
    There are a few differences installing it to XAMPP then to MAMP. A few twists were needed.
    I have seen this question posted on XAMPP forum quite a few times and I would like to post a tutorial there, may I have your permission to add the twist to your tutorial ?

    Like

  2. Hey Rich, I am glad you found my post useful. 😉 Feel free to use any content from my post here. You could even write a new post (specific to XAMPP) and post your blog post link to my comment section here, whichever is more clear to the readers to follow the steps. =)

    Like

  3. After looking into a number of the blog posts onn your weeb site, I seriously appreciate your way of
    writing a blog. I book-marked it to myy bookmark website list
    and will be checking back soon. Please check out my website as
    well and tell me how you feel.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s