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.
http://bart.eaccelerator.net/

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: http://pecl.php.net/package/APC)
  
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
wget http://pecl.php.net/get/APC-3.1.9.tgz


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 

phpize
./configure
make
make test
make install



4. Create APC config filenano /etc/php.d/apc.ini
Add to file

extension=apc.so
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64M
apc.max_file_size = 10M
apc.stat=1

Further information on advanced tweaking of configuration items here: http://www.php.net/manual/en/apc.configuration.php
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
phpinfo();
?>
 
Save and Exit

Launch from web browser: http://yourserver.com/phpinfo.php
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: http://pecl.php.net/package/APC)

Check the APC monitor

Launch from web browser: http://yourserver.com/apc.php
*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.

-Noveck