Alternative PHP Cache (APC) is a free, open source framework that optimizes PHP intermediate code and caches data and compiled code from the PHP bytecode compiler in shared memory. What this means is that APC reads your PHP files, parses them into a more efficient binary format and then caches them in memory so that each request for your PHP files and PHP library files can be fetch from the parsed cache. This will generally lead to a speed increase when serving a PHP site, especially one with a lot of library files. APC, allows your web server to save the compiled PHP so it can skip that compiling step. This can give your server a huge performance boost.
Please take the backup of php directory first because if anything goes wrong you can revert your configuration and then use the following steps to install the apc extension :-
First of all we need to download the APC code from the PHP PECL library. So change directory to somewhere like /home or /usr/local/ and then get the latest version like so
[root@piyush ~]# cd /opt
[root@piyush opt]# wget http://pecl.php.net/get/APC
This will always get the latest version, downloaded APC-3.0.16.tgz like so: And then you need to extract the files:
[root@piyush opt]# tar -zxvf APC-3.0.16.tgz
[root@piyush opt]# cd APC-3.0.16
The next step is to run the “phpize” command. This requires that you have PHP development package installed(Php-devel,. Installed by running “yum install php-devel”).
[root@piyush APC-3.0.16]# phpize
Then configure APC, telling it where the executable file php-config is. If you don’t know where this is, then do this and it will return something like:
[root@piyush APC-3.0.16]# whereis php-config
php-config: /usr/bin/php-config
And then run the configure command like :-
[root@piyush APC-3.0.16]# ./configure –enable-apc –enable-apc-mmap –with-apxs=/usr/sbin/apxs(your apache apxs path) –with-php-config=/usr/bin/php-config (your php-config path)
[root@piyush APC-3.0.16]# make
[root@piyush APC-3.0.16]# make install
Libraries have been installed in [ /opt/APC-3.0.16/modules]. Check your php.ini location by following command.
[root@piyush APC-3.0.16]# php -i | grep php.ini
Now open php.ini file in your favorite editor, And go to the last line and paste the following :-
[root@piyush APC-3.0.16]# vi /etc/php.ini
extension=”apc.so”
Now restart your apache web server.
[root@piyush APC-3.0.16]# /etc/init.d/httpd restart
The APC cache will now be enabled. You can verify this by creating a script or custom page which calls the phpinfo() command and looking for the APC section. It will have been switched on by default by adding a “extension=apc.so” line to your /etc/php.ini file.
=============================================================================


