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.

OSX-Mavericks-Icon

Mavericks Instructions

If you’re running Mac OS X Mavericks Server, see these articles about adding PHP extensions:

If you’ve previously installed this extension using instructions on this page, read this article to upgrade PHP extensions for Mavericks server.

The following steps are performed in the Terminal:

Force MacPorts to update:

sudo port -v selfupdate

Installing memcached and php5-memcache

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/

Installing php5-apc

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/

Adding memcache and apc to Apache

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:

6 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.

  3. making cup of coffee: 4 minutes
    installing memcache & APC : 3 minutes

    now looking for an APC for my coffe machine and i’m in bussines

    tnx !

  4. Pingback: Install memcache and APC on Mavericks Server 3 (Mac OS X 10.9) | Garbage In Garbage Out : Tech Blog

Leave a Reply

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