Enabling and disabling PHP’s APC cache on a per Virtual Host level in Apache

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 11, 2011

Follow me on Twitter as @mattiasgeniar

On some systems you want APC to work for a few Virtual Hosts, but not all – as it may break things like phpMyAdmin.

You can do that by disabling the APC “cache_by_default” option globally. In your apc-config file (usually /etc/php.d/apc.ini or somewhere along your general /etc/php.ini file) you disable the default caching.

[apc]
apc.cache_by_default = 0 

And 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

Notice the difference in the apc.ini config where the value is set to ‘0’ (zero). When passing “flags” to PHP via the Virtual Host or .htaccess config, it’s either On (=1) or Off (=0).



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.