APC (Alternative PHP Cache) is a free, open, and robust framework for caching and optimizing PHP intermediate code. APC is a great tool to speed up a php driven site and I can’t even think of a big site running on a php framework without an opcode cache (other good choices are eaccelerator or xcache). Why would not everyone want to use this? The reason why this is not enabled by default everywhere is because in certain situations it can break things. Most peoples will not see any problems, but still, if you run a server with many clients sharing the same apache service this might be a problem (as the apc module loading it is a server-wide config). This post will show how we can use APC globally and disable it for some vhosts (that might have a problem with using APC) or the reverse to just use it one a special vhost that might need this.
I’ll assume that you have installed apc already, if this is not the case this will probably be something as simple as running
pecl install apc
or downloading the archive from pecl and running:
phpize; ./configure; make; make install
The APC extension needs to be enabled either in php.ini or in one included file with a line like this:
extension=apc.so
there are many other parameters that apc can be fine tuned (see the official doc for more info), but without any other change, just with this line apc will be enabled on all the vhosts on the server.
Disabling some vhosts from using APC
- if we want to disable APC for a particular vhost we just have to add to the vhost config or to .htaccess:
php_flag apc.cache_by_default Off
Enabling APC only on some vhosts
- if we want to have APC disabled by default globally we will have in php.ini:
extension=apc.so
[apc]
apc.cache_by_default=0 # disable by default
... other apc settings...
and we will enable APC for the particular vhost config or using .htaccess using:
php_flag apc.cache_by_default On
Hopefully you found this post useful and this will give you a reason to use APC with more confidence knowing that you have the granularity to disable/enable it as needed in a shared environment.

Hi,
I tried your approach, but it seems not to work. When I set “cache_by_default” to 0, a phpinfo on every VHost will show this config as On. I could not get it to work.
Apache2 on Debian Lenny.
Best regards, Tom
Same for me, not work.
Works works
My problem was a cache problem on my browser
APC should be enabled by default | Linux Sysadmin Blog // Apr 1, 2011 at 2:36 pm
[...] Posts: Enable/Disable APC on virtual host levelGoogle will use site performance and page load speed in SERP ranking – sysadmin SEO here we [...]
WordPress, suPHP, and Ubuntu Server 10.04 « Mike Beach // Nov 12, 2011 at 10:28 am
[...] it is supposedly possible to disable it on a per-VirtualHost basis. I haven’t tested this [...]
APC should be enabled by default | ENJOY // Jan 15, 2012 at 5:47 am
[...] up from plain PHP. A very simple step-by-step intro on how you can install APC can be found on this older post. Now here is the question a good friend of mine asked me a while ago: why is APC not enabled by [...]
Hi, i tried this method of “Enabling APC only on some vhosts”, the thing is, APC still allocates and reserves memory for domains that don’t end up using APC. It just reserves it, pointlessly, without it being used? My apc.php file confirms this, as do my memory usage readings. Is there a way to COMPLETELY disable APC. As in, where it doesn’t allocated or reserve ANY memory for those domains with php_flag apc.cache_by_default On ? Any insight would be appreciated. thank you.
sorry, “without” php_flag apc.cache_by_default On