Alternate PHP Cache – Installation and Basic Know How

Well, when you are reviewing performance optimization of your website you sir can’t neglect APC. If you haven’t heard about it, here’s a quick break –

“The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.”

So you have your Data part optimized using Memcache and now you have an option to optimize intermediate code. I liked the idea the very first time i heard it.

BTW it’s very simple to install on CentOS or Ubuntu. I will guide you through Ubuntu 10.04 installation process for APC.

Step 1: Sudo pecl install apc

i got something like missing phpize- solved here   , PCRE missing – solved here

After this APC installer asks you following questions :

Enable internal debugging in APC [no] : 
Enable per request file info about files used from the APC cache [no] : 
Enable spin locks (EXPERIMENTAL) [no] : 
Enable memory protection (EXPERIMENTAL) [no] : 
Enable pthread mutexes (default) [yes] : 
Enable pthread read/write locks (EXPERIMENTAL) [no] :

I pressed <Enter> on all of them 🙂

Step 2: Add to php.ini

On my system php.ini is located @ /etc/php5/apache2/php.ini

Step 3 : restart apache

sudo /etc/init.d/apache2 restart

Step 4 : Sym link apc.php to www dir

sudo ln -s /usr/share/php5/apc.php /var/www/apc.php

Step 5: point your browser to localhost/apc.php

You must see basic stats , but if you have GD enabled hmm its really colorful.

This was a basic installation.

Some Runtime configuration changes must be kept in mind like apc.shm_size and apc.stat. Get more info on these settings and then choose what is best for you.





Missing PCRE dependency ?

Quick one , If you are installing APC or any other Package through pear and you get something like this :

In file included from /tmp/pear/temp/APC/apc.c:44:
/usr/include/php5/ext/pcre/php_pcre.h:29: fatal error: pcre.h: No such file or directory
compilation terminated.

Here is the solution for that:

yum install pcre-devel or apt-get install libpcre3-dev

just to be sure you don’t miss anything else , this is the quick run down of what to install in order to get basic php packages installed:

sudo apt-get install php5-pear php5-dev libpcre3-dev

Hope it helps you !