Speeding up PHP with APC (NOT eAccelerator) in Debian Squeeze running php 5 and apache 2

Jul 27th, 2012 | By | Category: Internet, Linux / Freebsd

Well today my server was being killed by something or other and after 30 minutes of trying to track down what it was I decided to spend my time optimizing my server and implementing a proper caching mechanism (finally!).  I come from a BSD background and we ran eAccelerator on all of our servers so that is the first place I went and my adventure into the world of eAccelerator running on a Debian 64 machine with apache 2, nginx and php 5.3 lasted about an hour before I clued into the fact that it shoudlnt’ be this difficult.  Setup was relatively straight forward and nothing went wrong until I turned it on and was greeted to an apache error log that looked like this:

[Fri Jul 27 08:05:23 2012] [notice] child pid 11205 exit signal Segmentation fault (11)

repeated 5 times per second.  All pages load up with a 502 error message.  I was kind of excited at first as I saw my server loads drop to .11 and then I loaded a page and saw why, womp womp womp.

Soo it took me about 10 minutes of fooling around to realize that eAccelerator was as piece of shit in my environment and I wasted no more time looking for an alternative.  Luckily I did as I see that APC produces better results anyways and is being incorporated by default into php 6, so there’s gotta be a good reason for that.

Anyways, the installation for apc was insanely simpler, I did it with a little apt-get install php-apc and then tweaked the configuration a little bit so my .ini file looks like this:

extension=apc.so
apc.shm_size=128
apc.rfc1867 = on
apc.enabled = 1
apc.max_file_size = 2

 

Now to put your shm size that high you’re going to need to adjust your kernel.shmmax setting with sysctl like this:

sysctl -w kernel.shmmax=268435456

You should read up about what this does before you do it, and you might not need it that high but I read a few articles today saying that at the default value of 16 or 32 MB it really isn’t being used to it’s potential with a server that is hosting a lot of sites, running a lot of scripts and getting a lot of traffic.  So look into what’s appropriate for you.

Also that if you are seeing some strange errors in your log files and you have values like 128M instead of 128 you should remove the M on the end.. There are a lot of tutorials that will instruct you to put the M on the end and apparently that’s not the way it’s done any more and can cause errors.

Hope this helps

 

Tags: , , , , ,

Leave a Comment