There’s a lot of conflicting information out there on how to install the APC opcode cache on a CentOS 5.6 box. Here’s how I did it:

This tutorial assumes you’re running CentOS 5.6 on a dedicated server, and that you have superuser (root) access. These instructions may also worked in a VPS or shared hosting environment, but if you run into trouble, you should contact your provider’s tech support to see if they have any alternative steps you should take.

First, you need to make sure the following packages are installed:

Because you’re going to be compiling a package, you’ll need a C compiler (like gcc) and make. The easiest way to install all the right development tools is with:

Be sure to include those quotes.

Now you’re ready to download and untar the package:

Now it’s time to set it up!

Take note of where php-config is located (it’s usually in /usr/bin/php-config) as you’ll need it in the next step. If it’s in a different location, use that for the php-config path below:

Next, if you have an /etc/php.d/ directory on your server, create a file called /etc/php.d/apc.ini to store all your configuration settings (if it already exists, you can just edit the existing one). If you don’t have an /etc/php.d/ directory, you can add these configuration settings to your existing php.ini file, which is usually located at /etc/php.ini.

Here’s an example of my apc.ini file, with lots of comments for some guidance. This is a pretty straightforward configuration, so feel free to copy and paste:

The final step is to restart Apache with either:

or

To make sure APC is running, create a php file somewhere in your web root that simply contains:

then load the file and scroll down to the APC section to verify that it’s enabled.

For some cool statistics, copy the usr/local/src/APC-3.1.9/apc.php file somewhere in your web root, and then open it in your browser. Edit the file on the server if you’d like to add a password and enable login to see more details. Here’s a peek at what it looks like:

APC Info Page

Congratulations! You’ve just installed APC on CentOS 5.6!

Further Reading