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:

This entry was posted in Front Page, How-To, Technology and tagged , by Chris Brewer. Bookmark the permalink.

About Chris Brewer

My most recent work and biography is at http://chrisbrewer.me (my home page, by the way). Chris Brewer has worked in both industry and academia for years at the intersection of information systems and communications. His background is in areas ranging from technical consulting with Fortune 500 companies, developing award-winning web sites, publishing the Denver Scene, and operating small business concerns. Chris has a unique mix of in-depth technical skills ranging from web and database development to server administration, and strong creative skills in traditional and rich media. Chris actively illustrates his love for the impact and promise of web-based media by fusing creative and technical inputs into seamless integrated output. Chris is also a dynamic lecturer and an innovative technical instructor, and holds an undergraduate business degree from the University of Colorado.

4 thoughts on “Install memcache and APC on Mac OS X Server (snow leopard 10.6, Lion 10.7, Mountain Lion 10.8)

  1. I know this is an old thread, but it’s right on track for my PowerPC G5 based os x web server. I followed the steps above, and everything seems to have worked fine. However, only memcache is showing up in the info.php output — APC isn’t there. The version of php.ini in /usr/local/php5/lib/ appears to be the one showing up when I load info.php, but just to check it, I also added the extensions to /etc/php.ini. Still I get no APC blocks showing up after restarting apache.

    Any advice?

  2. Additional note: because it’s a G5 machine, I’m running osx leopard server. Macports seems to have compiled the ppc versions, so I’m not sure why this would matter.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>