Monday, February 15, 2010

APC.php not Working

I was getting a new server up and running and wanted to install APC (Alternative PHP Cache). Things were going great. I even ran phpinfo() and noted that APC had an entry. Everything was super, right?

I wanted more confirmation, so I used SSH, located apc.php and copied it to a domain for public access. I wanted to know how well APC was working for me. However, it wouldn't run. It sent back errors and when I tried to debug it I got no where.

Turns out, APC wasn't really doing much of anything. I had PHP installed and running as a CGI instead of an Apache Module. If PHP runs as a CGI, APC closes at the end of each script run and the cache is lost—it doesn't make much sense to use APC in this situation. While runing as a CGI has some security benefits you lose a bit of performance and, more importantly to me, APC doesn't really work.

I use WHM and so I went to "Main >> Service Configuration >> Apache Configuration" and then changed the PHP 5 handler to DSO. This solved the problem and apc.php loaded just fine the next time I tried. And it even had some pretty stats for me to see.


Anonymous said...

I installed APC today and was having the exact same problem - I just couldn't figure out why the opcode cache wasn't having any effect.

I don't think I would have solved this if I hadn't found your post. Thank you!


Eric said...

Glad I could help!

Eric said...

Thank you for writing this post! I spent the better part of this morning trying to figure out why APC wasn't working properly on my server, to no avail. Then, I read your post, and had APC working properly in about 2 minutes.

Anonymous said...

THANK YOU SO MUCH! Spent hours trying to figure this out and finally I found your post. Thanks again!

Anonymous said...

Wow! I've banged my head against the wall for over a year trying to figure this out. Gave up so many times. And tonight I was about to give up again... and then I stumbled across your post. Yay!!!!!! It actually works!!!!!! Thank you so much! =D

Neo said...

I also installed APC successfully but when I run apc.php file, it always shows 1 hit and 1 miss. When I go to Service Configuration as you said, I cannot see DSO for PHP5 Handler. I have: suphp, cgi, fcgi and none. Can you please advise?