Tag Archives: apc

Installing Alternative PHP Cache (APC) on Mac OS X Lion

The APC extension should be a straightforward PECL install, but sadly it does not work on Mac OS X Lion. Attempting to install will result in make errors similar to the following:

In file included from /private/tmp/APC/apc.c:44:
/usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
In file included from /private/tmp/APC/apc.c:44:
/usr/include/php/ext/pcre/php_pcre.h:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:38: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/php/ext/pcre/php_pcre.h:44: error: expected specifier-qualifier-list before ‘pcre’
/private/tmp/APC/apc.c:393: error: expected specifier-qualifier-list before ‘pcre’
/private/tmp/APC/apc.c: In function ‘apc_regex_compile_array’:
/private/tmp/APC/apc.c:454: error: ‘apc_regex’ has no member named ‘preg’
/private/tmp/APC/apc.c:454: error: ‘apc_regex’ has no member named ‘preg’
/private/tmp/APC/apc.c:455: error: ‘apc_regex’ has no member named ‘nreg’
/private/tmp/APC/apc.c:455: error: ‘apc_regex’ has no member named ‘nreg’
/private/tmp/APC/apc.c: In function ‘apc_regex_match_array’:
/private/tmp/APC/apc.c:487: error: ‘apc_regex’ has no member named ‘preg’
/private/tmp/APC/apc.c:487: error: ‘apc_regex’ has no member named ‘preg’
/private/tmp/APC/apc.c:488: error: ‘apc_regex’ has no member named ‘nreg’
/private/tmp/APC/apc.c:488: error: ‘apc_regex’ has no member named ‘nreg’
make: *** [apc.lo] Error 1
ERROR: `make' failed

Thankfully, the solution is simple. To being with, make sure you have Xcode installed. If you have xCode 4.3 or above, make sure you have the command line tools installed.

APC requires PCRE libraries and header files to be available, so we can download and install these from source:

./configure
make
sudo make install

Next, we can install the APC extension using the normal PECL route:

sudo pecl install apc

Confirm that you have the following line in your php.ini file:

extension=apc.so

Restart Apache, if required:

sudo apachectl graceful

You should now have APC available, and you can confirm this by looking at your phpinfo output:

APC PHP info


Want advice on building better software? Join my mailing list…


Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn