Install Alternative PHP Cache in CentOS

APC is a cache system which stores compiled PHP code, also allows to store user data allowing the web server to serve a greater number of requests per second, it's a worth noting that a wrong configuration of it can slow the response process, so it is important to adjust the cache parameters until finding the proper performance.

The method described below requires the PEAR extension, to install PEAR on CentOS-5.6 follow the instructions from step 5 of the article: Upgrading to PHP 5.3. x on CentOS

Install APC
# yum -y install gcc make php-devel pcre pcre-devel && pecl install apc
Enable APC
# echo "extension=apc.so">/etc/php.d/apc.ini
Restart Apache
# service httpd graceful
Check
$ php -i | grep apc
Additional .ini files parsed => /etc/php.d/apc.ini,
apc
MMAP File Mask => /apc.shm.8Il1zO
apc.cache_by_default => On => On
...

Web interface

Create dir in the root of the web server
# mkdir /var/www/apc
Copy apc.php file
# cp -v /usr/share/pear/apc.php /var/www/apc/
Set password
# vim +42 /var/www/apc/apc.php
Create a VirtualHost

For more information on how to create a VirtualHost see article: Install and configure Apache HTTP server

The admin page only will be available to the IP1, 2 and 3

<VirtualHost *:80> 
        Options FollowSymLinks -ExecCGI
        ServerName apc.midominio.com
        DirectoryIndex apc.php
        DocumentRoot /var/www/apc
<Directory>
        Order Deny,Allow
        Deny from all
        Allow from IP1
        Allow from IP2
        Allow from IP3
</Directory> 
</VirtualHost> 

Further readings

-APC: Settings at run time

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.