Turning PHP APC on or off per site

The Alternative PHP Cache (APC) is a fantastic free and open opcode cache for PHP and does a great job at caching and optimizing PHP intermediate code. We all know what it does and how it works.
Sometimes we don’t want it enabled for all sites on a server (Using php.ini or conf.d/apc.ini), for example, you have a dev site and a live site on the same server. Having APC enabled on a dev site can be a little annoying.

Edit your php.ini or conf.d/apc.ini and disable APC by changing

[codesyntax lang=”apache”]
apc.cache_by_default 1

to (Or, if that line doesn’t exist, just add the following;)

[codesyntax lang=”apache”]
apc.cache_by_default 0

Now, in our live site (or site we want APC to be active on) we add the following to the .htaccess or vhost config

[codesyntax lang=”apache”]
php_flag apc.cache_by_default On

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *