How to enable apc extension under command line php interface (Debian and Ubuntu)

APC is a cache speeding up php execution and allows you to speed up applications by in-memory caching.

Installation of APC on debian / ubuntu

We install the extension using pecl packaging tool (it will download and compile the module).

pecl install apc

If you are asked if you need apxs say no.

Make sure module is enabled in php.ini for command line interface. On debian like systems check if installer did not add anything to /etc/php5/cli/conf.d or /etc/php5/cli/php.ini

If there is no mention of edit


Enabling APC for the command line interpreter

We have to add just two lines to the appropriate ini file:

apc.enabled = 1
apc.enable_cli = 1 

Now you can check if command line php really loads it by executing

php -i | grep 'apc'

If it shows anything then you are done, otherwise you have to make sure you are editing the correct ini file so try to look for ini path in

php -i


Good points guys, thanks for

Good points guys, thanks for that. The main reason i enable caches for command line is to be able to use the use APC cache in unit tests. Then i dont have to mock stuff that depends on APC .... and i tend to use it a lot :)

Thanks for comments :)


2013-03-16 21:04

Unfortunately enabling APC

Unfortunately enabling APC for PHP CLI applications will only SLOW them down. It's because the cache is created/destroyed for every call to the script (e.t. by cron for example).
The only way to accelerate a php cli script vith APC or eAccelerator is to call it via apache server as web-app.
But you need to test, because then you'll have some overhead, due to creating sockets. You can use wget or other native compiled client to issue 'HTTP GET' command so you'll need to put wget with proper request uri inp lace of the php cli script.
Why native compiled client -> because the goal is to save you from overhead due to script parsing.

2013-03-15 11:19

It's worth noting that the

It's worth noting that the PHP page on APC points out the cache is created on each CGI request (

2011-05-15 12:58

Post new comment


About the author

Artur Ejsmont

Hi, my name is Artur Ejsmont,
welcome to my blog. I am a passionate software engineer living in Sydney and working for Yahoo!

Web Scalability for Startup Engineers

If you are into technology, you can order my book Web Scalability for Startup Engineers on Amazon. I would love to hear what are your thoughts so please feel free to drop me a line or leave a comment.

Follow my RSS