Friday, January 13, 2012

Installation of APC on php 5.3 (CentOS 5.x)

My previous blog entry used Eaccelerator as a php cache, but it does not appear to be actively maintaned.

In my research for a suitable and robust alternative, I recognized that a lot of large sites were using APC, and it was compatible with my desired application (Moodle)

APC (Alternative PHP Cache) is a free, open, and robust framework for caching and optimizing PHP intermediate code. (taken from:
In order to avoid installation conflicts from the base repository, it was much simpler to compile the APC package from source for the php 5.3 on a CentOS 5.x installation.

0. Login as root

1. Go to temp folder and download the latest tarball cd /temp

2. Extract to temp
tar xzvf APC-3.1.9.tgz
cd APC-3.1.9

3. Configure and Install
**amended on 05-07-2012, added pcre-devel install as suggested by yaroslav.

yum install pcre-devel 

make test
make install

4. Create APC config filenano /etc/php.d/apc.ini
Add to file
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.max_file_size = 10M

Further information on advanced tweaking of configuration items here:
5. Restart the webserver
service httpd restart

6. Check to see if APC was installed properly
nano /var/www/html/phpinfo.php

Add to file

< php
Save and Exit

Launch from web browser:
The APC configuration item should be found on the page.

7. Install the APC monitor

Copy APC Monitoring file into web root
cp /temp/APC-3.1.9/apc.php /var/www/html/

(There are options to secure this file, see the website for further details:

Check the APC monitor

Launch from web browser:
*A page should load displaying cache information and host status.

That's it. A quick and painless method of installing the APC Cache for php 5.3 on CentOS 5.x.