Configure PHP APC to speed up Drupal

The APC PHP extension is a PECL extension that saves compiled versions of your code in memory, in order that your PHP code is not compiled on every page load.

Below I provide an overview of how I configured APC on my Debian server to improve the performance of my Drupal site.

My Debian server was already running Apache 2 and PHP 5, so installing PHP APC was as easy as doing the following:
apt-get install php-apc

This installs the APC PHP extension, but it is not yet enabled. In order to enable and configure it, you have to enable the apc.ini file. The apc.ini file is located in the following location:
/etc/php5/apache2/conf.d/apc.ini

Open the file using your favorite editor, and add the following content:
extension=apc.so
apc.enabled=1

Don't forget to restart your Apache server so that the changes are applied.

You can find some more tips on optimizing APC for Drupal on the following site: http://xerosphere.net/optimizing-apc-for-drupal However, the default values correspond pretty well with the recommended values.

In order to see the status of APC, the Debian installation comes with an apc.php file which is meant just for that. However because of security reasons, the file is not put in your web root by default. In order to copy the file to your web root, do the following:

  • Debian 6: gzip -dc /usr/share/doc/php-apc/apc.php.gz > /var/www/apc.php
  • Debian 7: cp /usr/share/doc/php-apc/apc.php /var/www/

Make sure that the apc.php is stored in a directory that is well protected, since it leaks sensitive information about your website. Put it inside a protected directory or in a VirtualHost that is only used for administrative tools.

The apc.php file also has a section which allows you to log in and to view more details. This section is protected with a username and password. Edit the apc.php file to change the username and the password.

Tags: 

Share