Web/database development and more...
« How to log request processing times in ApacheHow to control fan speed & noise on the mac pro »

How to install the APC PHP Cache on Debian (Lenny or Squeeze)


How to install the APC PHP Cache on Debian (Lenny or Squeeze)

  01:50:00 am, by fplanque   , Categories: PHP, Linux stuff
APC PHP Cache Control Panel
The APC PHP Cache Control Panel

The APC cache can significantly improve your PHP script performance, just by installing it, which basically takes 5 minutes! (Plus, it’s actually supported by the core PHP developers and will probably be integrated into PHP6…)

Here’s what I did on my Debian Lenny box…

First you may want to have a reference benchmark to see if it actually improves:


ab -c5 -n100 http://www.yoursite.com/yourscript.php

Now install the APC package:


aptitude install php-apc

Now, restart apache:


/etc/init.d/apache2 restart

Now, you can run your benchmark again and see the difference! Tada! :)

APC comes with a control panel script, that allows you to check cache usage. Here’s how to make it available on your web root (for example):


gunzip /usr/share/doc/php-apc/apc.php.gz
ln -s /usr/share/doc/php-apc/apc.php /var/www/apc.php

Note that you should also have the php-gd package installed in order to get nice charts! ;)


Comment from: Walter Cruz [Visitor]  
Walter Cruz

Good. I was using xcache, but switched to apc. But by setup is not that simple ;) I’m in a linode VPS with 360 MB of RAM, and with that setup, is better to use php as fastcgi to get eeverything under control.. A post that explains almost everything about it: http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/

12/12/09 @ 21:20
Comment from: admin [Member]  

Interesting, for me it was so simple to set up I couldn’t believe it ;)

12/12/09 @ 22:11
Comment from: Dee [Visitor]

Hello, I’m a Linux newbie. Thank you for this tutorial.

Does “yoursite” need to be replaced by the name of my site in the command below? Can IP address be used? What is in “yoursite.php”

ab -c5 -n100 http://www.yoursite.com/yourscript.php

Also, how did you get the chart above? Is there a link or command to get there? Thank you.

04/05/11 @ 17:31
Comment from: GRL [Visitor]

Thanks, this was useful for me.

01/22/12 @ 22:16
Comment from: barzi [Visitor]

Hi, can you give an update the post for squeeze, where /usr/share/doc/php-apc/apc.php.gz
does not exist? Cheers

09/16/12 @ 01:21