Ramblings on technology with a dash of social commentary
RSS icon Email icon Home icon
  • How to install PHP APC extension on Snow Leopard

    Posted on August 11th, 2011 phpguru No comments

    I followed several posts on the Apple Suppor forum to install APC on Snow Leopard (not Server, but this forum seems much more appropriate as I am using Snow Leopard on my local MBP 17 for serious web development, trying to match my Ubuntu Server config as closely as possible.)

    Most notably, these:


    as well as


    I had to instal PCRE 8.12 before APC 3.1.9 install would work. Wincent has perfect instructions for that.

    Now back in my APC source directory, doing phpize and ./configure resulted in test failures; I realized that the recommended way of installing APC is via pecl channel-discover pecl.php.net
    pecl install APC

    This succeeded: Build process completed successfully
    Installing '/usr/include/php/ext/apc/apc_serializer.h'
    Installing '/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so'
    install ok: channel://pecl.php.net/APC-3.1.9
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=apc.so" to php.ini

    Okay, so I add extension=apc.so to php.ini and restart apache. sh-3.2# php -i | grep apc
    apc.cache_by_default => On => On
    apc.canonicalize => On => On
    apc.coredump_unmap => Off => Off
    apc.enable_cli => Off => Off
    apc.enabled => On => On
    apc.file_md5 => Off => Off
    apc.file_update_protection => 2 => 2
    apc.filters => no value => no value
    apc.gc_ttl => 3600 => 3600
    apc.include_once_override => Off => Off
    apc.lazy_classes => Off => Off
    apc.lazy_functions => Off => Off
    apc.max_file_size => 1M => 1M
    apc.mmap_file_mask => no value => no value
    apc.num_files_hint => 1000 => 1000
    apc.preload_path => no value => no value
    apc.report_autofilter => Off => Off
    apc.rfc1867 => Off => Off
    apc.rfc1867_freq => 0 => 0
    apc.rfc1867_prefix => upload_ => upload_
    apc.rfc1867_ttl => 3600 => 3600
    apc.serializer => default => default
    apc.shm_segments => 1 => 1
    apc.shm_size => 32M => 32M
    apc.slam_defense => On => On
    apc.stat => On => On
    apc.stat_ctime => Off => Off
    apc.ttl => 0 => 0
    apc.use_request_time => On => On
    apc.user_entries_hint => 4096 => 4096
    apc.user_ttl => 0 => 0
    apc.write_lock => On => On

    So now we know, from the command line anyway, PHP CLI is reporting it has APC installed.

    Now here’s the interesting part… from Apache (e.g. trying to run any local PHP file http://localhost/info.php for example) I just get a white page of death.

    If I comment that extension out and restart Apache, PHP files work again.

    Hmm, lets look at the error.tail -f error_log
    shows: Fatal error: Unknown: apc_fcntl_unlock failed: in Unknown on line 0

    I google that and find this bug report, where it is stated that a patch is available for apc_lock.h.

    I go back to the PECL APC source site and browse the sources in trunk, find the apc_lock.h file, download it, put it into my APC-3.1.9 source directory and run phpize
    make clean
    make install
    apachectl restart

    Note that `make clean` is the magic bit there since we already installed APC from these sources, we need to make a new fresh install from these same sources.

    Now everything is working happily again.

    Good luck with yours!

    Leave a reply