Installing APC On BSD Variants

Alternative PHP Cache is a PHP caching mechanism (like Turck mmCache, eAccelerator, etc.) that is being developed directly by PHP developers. In fact, PHP 6.0 is going to include APC Cache in it’s core framework, so it’s certainly something PHP developers/admins should start looking at.

Anyway, if you install APC Cache and Apache fails to start afterwards, check your Apache error log to see if you get something like this:

[Thu Mar 23 15:18:28 2006] [apc-error] apc_shm_create: shmget(0, 67108864,914) failed: Invalid argument. It is possible that the chosen SHM segment size is higher than the operation system allows. Linux has usually a default limit of 32MB per segment.
PHP Warning: Unknown(): Unable to load dynamic library './/usr/local/lib/php/apc.so' - (null) in Unknown on line 0

Most BSD variants (including Mac OS X Server in my case) don’t allow much shared memory to be allocated by default. Lucky, it’s an easy fix…

My OS had a default allowance of 4MB max for shared memory. You can alter that by adding this to your /etc/sysctl.conf file (or creating it if it doesn’t exist):

My new /etc/sysctl.conf file…

kern.sysv.shmmax=134217728
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.sysv.shmall=32768

shmall should be shmmax/4096

So the above config will let you use up to 128MB for shared memory.

You can’t dynamically set the shared memory kernel variables with the sysctl command because once it’s set, it can’t be altered. Because of that, you must reboot your server after you edit the sysctl.conf file…

Update

I just realized that *only* editing sysctl.conf works on Mac OS X. For Mac OS X Server, you need to comment out the kern.sysv.shm* lines in /etc/rc (in Mac OS X Server those commands are called before sysctl.conf is read for some reason).

Leave a Reply

Your email address will not be published.