Note: This is an old article, and the APC Opcode Cache is now abandoned. Strongly consider installing Zend OPcache instead. APC is now effectively unsupported, although you can still install and use it. Furthermore, OPcache is included in the PHP core as of PHP 5.5, and OPcache is also available and fully supported for PHP versions going back to 5.2. The APC user cache can be installed as APCu if you need its data store functionality.
An opcode cache like APC allows your web server to use compiled PHP scripts repeatedly instead of having to recompile them over and over again. This can reduce your server’s load and response times.
(Shown here on Ubuntu 12.04, using the latest APC version (3.1.13). Just running apt-get install php-apc gives you version 3.1.7.)
$ wget http://pecl.php.net/get/APC $ apt-get install build-essential libpcre3-dev $ tar -xvzf APC-3.1.13.tgz $ cd APC-3.1.13 $ ./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config $ make $ make test $ make install
To set the APC configuration, edit /etc/php5/conf.d/apc.ini:
extension=apc.so apc.mmap_file_mask=/apc.shm.XXXXXX apc.shm_size=128M apc.ttl = 3600 apc.user_ttl = 7200 apc.gc_ttl = 3600
You can also unzip the apc.php status page (/usr/share/doc/php-apc/apc.php.gz) and put it in a secure location for viewing with a web browser. This page gives you a nice graphical representation of your APC cache and settings.