You are here

installing APC on Ubuntu linux and benchmarking Drupal 6 performance improvement

There are several different PHP accelerators to choose from, but according to wikipedia "APC is quickly becoming the de-facto standard PHP caching mechanism as it will be included built-in to the core of PHP starting with PHP 6".

I recently put together a new development webserver in a virtualbox virtual machine, and as I was setting it up I thought I'd take the opportunity to test how much difference APC actually makes to a simple Drupal site.


I was using Ubuntu server. On newer releases APC is available from the package manager...

$ apt-cache search php-apc php-apc - APC (Alternative PHP Cache) module for PHP 5 $ sudo apt-get install php-apc

...however I'm using Ubuntu 8.04 LTS (Hardy Heron) and there's no apc-php package. It's not hard to install via PECL / PEAR though. First some dependencies need to be installed, then PECL can be used to install APC.

$ sudo apt-get install php-pear php5-dev apache2-threaded-dev build-essential $ sudo pecl install apc

This last command will produce a ton of output, but one of the last lines will tell you to add this to your php.ini file (which you'll find in /etc/php5/apache2/php.ini) - you'll probably have to do so manually.

Restart apache, and you should see a new APC section in phpinfo() which will confirm it's enabled. There's a small php script which gives you some useful info about APC, which you'll find in /usr/share/php/apc.php - you could use a symlink to allow you to get to this file in your browser to see the stats and graphs it produces to tell you what files it has cached, and info on cache hits and misses.

What difference does it make?

I've left the APC default settings - which in my case was only 30mb of memory being used for cache, and run some basic tests using Apache Bench on a simple Drupal 6 site. The actual performance figures are not that important (this is a virtual machine on my laptop, not a production server), but it's interesting to see how much difference it makes turning APC on.

I tested two pages - the very simple homepage, and another page which displays a relatively long webform. The AB command I used was for 100 requests with 10 concurrent requests. e.g.

$ ab -n 100 -c 10 http://mytestsite.example/webform/

test of APC on a Drupal 6 site Test Requests / Second homepage (APC off) 2.78 webform (APC off) 1.72 homepage (APC on) 8.36 webform (APC on) 3.77 test of APC on a Drupal 6 site Test Milliseconds / Request homepage (APC off) 359.68 webform (APC off) 582.94 homepage (APC on) 119.61 webform (APC on) 265.41

You can see that the effect of APC on the simple homepage is more dramatic than on the webform page. This is almost certainly because the database has to do a lot more work to build the latter, and APC's not going to help on that front. However, we can say on the simple page APC makes Drupal perform almost 3 times faster. With the more database-heavy webform page, the improvement is slightly less - but we're still looking at a doubling in performance.

This is obviously not a hugely detailed test, but it certainly leaves me in no doubt that installing APC represents a quick and easy way to achieve a huge improvement in performance for Drupal sites.


Great article, thanks!

/usr/share/php/apc.php - you could use a symlink to allow you to get to this file in your browser

so if you're using the default /var/www as a valid docroot:

> cd /var/www
> sudo ln -s /usr/share/php/apc.php

would let you see the apc.php script at myserver/apc.php - perhaps http://localhost/apc.php


I tried to follow my own instructions above recently on a server running Ubuntu 8.04, and got this error:

> sudo pecl install apc
downloading APC-3.1.9.tgz ...
Starting to download APC-3.1.9.tgz (155,540 bytes)
.................................done: 155,540 bytes
54 source files, building
running: phpize
Cannot find config.m4.
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
ERROR: `phpize' failed

Not sure why this wasn't working - I think it's a newer version of APC, but that might not be the problem.

I had better luck downloading the package manually and installing it myself, as per instructions I found here:

...something along the lines of:

wget http: //
tar -xzvf APC-3.1.9.tgz
cd APC-3.1.9
./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
make test
make install

Thanks after reading your blog post I tried to install it on my server using Nginx not Apache. Then I wrote how I did it on my blog:

is this wordpress ?

Thanks for the great write up.

I’m running vTiger an open source CRM product and decided to use your advice to improve the performance of this php based application.

However, when I try to access the apc.php page to review the statistics it fails to load with the following message:

Oops! There’s been a problem with vtiger CRM
404 Not Found

Your requested a file or resource that does not exist on this server. You almost certainly mistyped something; check your browser’s address bar.
You can use the following links to:

Go back where you came from
Visit the site’s front page

If you are this site’s administrator, you may also:

Administer vtiger CRM

How do I get the apc.php page to load? Any ideas/thoughts would be much appreciated.


why is that?
care to explain?
just thought i ask