Easy & Quick PHP Memcache Install on Mac OSX Lion 10.7

I’m working on getting an existing site that’s using Drupal 7 up and running on my local 10.7.5 Mac. Unfortunately it is throwing a lot of errors that memcache is not installed. Well don’t worry, I found an easy and quick why to install memcache on to Lion.

Install PECL

If you have pecl installed then skip to Install Memcache.

PECL OAuth

A couple of projects I work on use the PECL OAuth component:

  1. Ensure you have installed Xcode from the Mac App Store
  2. Download the latest PCRE source code from http://sourceforge.net/projects/pcre/files/pcre/ and unzip to a folder on your desktop
  3. cd ~/Desktop/pcre-8.32
  4. ./configure
  5. sudo cp pcre.h /usr/include/
  6. Remove the pcre folder on your desktop as you don’t need it any more
  7. sudo pecl install oauth
  8. Edit/etc/php.ini add these lines to the end of the file:
    [oauth]
    extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/oauth.so"
  9. Restart apache: sudo apachectl -k graceful and check in the phpinfo that OAuth is now loaded.

 

Install Memcache

$ sudo pecl install memcache

It will display a bunch of output to the screen which is gibberish to most of us but should end with something similar to this

Build process completed successfully
Installing ‘/usr/lib/php/extensions/no-debug-non-zts-20090626/memcache.so’
install ok: channel://pecl.php.net/memcache-2.2.7
configuration option “php_ini” is not set to php.ini location
You should add “extension=memcache.so” to php.ini

Add Memcache to PHP

Now that we have memcache installed it’s time to tell PHP about it. How do we do this? Well we need to edit the php.ini file. You may not have one, in which case you will have a /etc/php.ini.default file. Please note that /private/etc is the same as /etc.  Copy or move the default file to php.ini. First change directories

$ cd /etc

Do you have the php.ini file?

$ls php.ini

If it said “ls: php.ini: No such file or directory” then pick the copy or move command to create the file.

$ sudo cp php.ini.default php.ini
$ sudo mv php.ini.default php.ini

Now we can edit the file and enable memcache

$ sudo vi php.ini

*Pick whatever editor you are comfortable with, I use vi.

Scroll down to the extensions section, if you are using vi editor hit {esc} and type “/Dynamic Extensions”  {return}. This should bring you down to the line needed. Scroll to the bottom of this section and add

extension=memcache.so

Save the file by hitting {esc} and type “x!” {return}

Now restart apache $ sudo apachectl -k graceful

Ok this should have done it. I hope this helped.

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.