How to install PHP APC in OS X

I assume you already have PEAR/PECL available. I am using the Mac OS X PHP environment that is provided by Apple’s XCode but it shouldn’t matter how you get your PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Currently the latest version of APC at point of writing is 3.1.6. Let’s get that:

[code lang=”bash”]kahwee:~ kahwee$ sudo pecl install apc-3.1.6
downloading APC-3.1.6.tgz …
Starting to download APC-3.1.6.tgz (148,835 bytes)
….done: 148,835 bytes
49 source files, building
…[/code]

If you get an error like the following:

[code lang=”bash”]…
/usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory
In file included from /private/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/temp/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/var/tmp/apache_mod_php/apache_mod_php-53~1/Build/tmp/pear/temp/APC/apc.c:369: error: expected specifier-qualifier-list before ‘pcre’
…[/code]

…it is because you do not have PCRE library headers. We can install that with Homebrew:

[code lang=”bash”]brew install pcre[/code]

After installing that, you should be able to successfully complete the PHP APC installation:

[code lang=”bash”]kahwee:~ kahwee$ sudo pecl install apc-3.1.6
downloading APC-3.1.6.tgz …
Starting to download APC-3.1.6.tgz (148,835 bytes)
….done: 148,835 bytes
49 source files, building

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

Finally, you can add “extension=apc.so” to the last line of php.ini, for my case I open the ini file in nano:

[code lang=”bash”]nano /etc/php.ini[/code]

I also added the following settings in php.ini:

[code lang=”bash”]apc.enabled=1
apc.shm_segments=1
apc.shm_size=32M
apc.cache_by_default=1
apc.stat=1
apc.rfc1867=1 //For Drupal upload progress.
apc.stat=7200 //2 hours[/code]

So to summarize, here’s what I did:

[code lang=”bash”]$ sudo pear update-channels
$ brew install pcre
$ sudo pecl install apc-3.1.6[/code]

This is tested on Mac OS X 10.6.5 Snow Leopard.

6 thoughts on “How to install PHP APC in OS X”

  1. Update:
    I got an minor error when trying to execute php command on the cli… i.e.

    PHP Warning: PHP Startup: apc.shm_size now uses M/G suffixes, please update
    your ini files in Unknown on line 0

    Fix it by changing:
    apc.shm_size=32MB (in php.ini)
    to
    apc.shm_size=32M

    …and the error disappeared =)

  2. Hi Greg, thanks for the note. I’ll update the post. I also switched to use homebrew now. MacPorts felt kinda heavy for me and I just got rid of it for a week and I’m liking homebrew so much more now.

  3. Many thanks. Following this guide Fixed my problems for following error on OSX snow leopard:

    make: *** [apc.lo] Error 1

Leave a Reply

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