Configure APC (Alternative PHP Cache) for LESS CPU load

Valic —  March 19, 2012 — Leave a comment

APC  Configuration:

Once you have installed following this tutorial  you need to configure it.

APC makes use of a shared memory segment to cache php scripts. This enables multiple processes to access the cache. You can configure how massive that segment is in megabytes:


By default,  APC will cache every php file requested by visitors to your website. On a typical server you will have lots of thousands of source files. So in the event you monitor the output of apc.php you will find that with time even 100MB of memory is not sufficient for APC. It will keep running  out of space as it tries to cache all the files.
To deal with this, APC will swap out old files from the cache according to this setting which specifies the time to live in seconds of files that have not been accessed recently:


You may prefer to cache only some of the files such as those used by the most popular websites on the server. To do that you must first set this option:


Then you can then enable it per Virtual Host you like, either in the general Virtual Host apache config or in the .htaccess file if you allow Overrides in the Apache config

php_flag apc.cache_by_default On

The advantage  is that you can specify a smaller shared memory size and still reduce CPU load significantly.


You can also set the apc.php to be available on the web:

ln -s /usr/share/php/apc.php apc.php

Then you can access the APC INFO page on http://your-ip/apc.php



Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

No Comments

Be the first to start the conversation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.