Install memcache and apc on Mac OS X Server (Snow Leopard 10.6, Lion 10.7, Mountain Lion 10.8)

Looking to speed up your SocialEngine, Drupal, or other PHP/MySQL web site? The combination of APC and Memcache can really speed up sites based on these platforms. If you’re an admin of a server running Mac OS X Server (10.6), here’s how to install APC and memcache on Mac OS X server:

Download and install MacPorts from http://macports.org.

The following steps are performed in the Terminal:

Force MacPorts to update:

sudo port -v selfupdate

Now, install memcached:
sudo port install memcached

Set memcached to load on startup:
sudo port load memcached

Install the PHP5 module for memcache:
sudo port install php5-memcache

Copy the newly created shared object for memcache into Mac OS X’s default PHP5 extension directory:
sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/memcache.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Install APC (Alternative PHP Cache):
sudo port install php5-apc

Copy the newly created shared object for APC into Mac OS X’s default PHP5 extension directory:
sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/apc.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Next, you need to edit php.ini to add the extensions. Find the phrase Dynamic Extensions, and add:

extension=memcache.so
extension=apc.so

And finally, restart Apache:
sudo apachectl restart

To confirm installation, create a new PHP document called phpinfo.php with the following contents:
< ?php phpinfo(); ?>

Point your browser to that file. If all went well, you’ll see these blocks:

Screen-shot-2011-01-23-at-5.37.56-PMScreen-shot-2011-01-23-at-5.37.41-PM