sam's bits

ramblings on technology and other stuff

Install and enable Alternative PHP Cache (APC) on Ubuntu 12.04 LTS

If you want to speed up your website, a good option (apart from code optimisation, HTTP request reduction and the likes) is to enable opcode caching on the server. Most blogs and other dynamic websites on the internet run with PHP. There are many PHP accelerators and APC is open source, pretty easy to install and has many configuration options.

For a heavy application consisting of a large source code base such as Drupal, you can expect around a 3x increase in page generation speed as a result. - List of PHP Accelerators on Wikipedia

First you need to install PEAR and dev packages, this is Ubuntu specific but similar on other platforms.

  • apt-get install php-pear
  • apt-get install php5-dev
  • apt-get install make
  • apt-get install apache2-prefork-dev

Once that’s done, install the APC module with pecl:

  • pecl install apc

Go with the defaults, if you don’t know better. If the module has been succesfully installed, don’t forget to add the extension to your php.ini somewhere:


Check out all the configuration options

Now that you’ve installed APC, just restart your webserver (e.g. sudo service apache2 restart) and your PHP is now “accelerated”! APC provides a web interface with detailed information on the cache (memory usage, hits & misses, cache entries). By default it is not accessible so you need to copy the file /usr/share/php/apc.php to somewhere you can browse to.

Categories: PHP, Ubuntu

Tags: php5, apc, apache2

Comments: 3 Comments



  • Comment by Anna Filina on 5 August 2013 3:36 pm

    On a fresh Ubuntu Server, you may also need

    apt-get install libpcre3-dev

  • Comment by Gerold, on 15 October 2013 3:54 pm


    that article really helped me to install APC and speed up my VPS.


  • Comment by Goldfinger on 25 January 2014 11:12 am

    apc-get install php-apc

Post a comment