Just another C3M Digital Server Network site

APC Alternative PHP Cache on a CPanel Server

PHP LogoAPC 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. Installing APC using the built in PECL package is a very convenient method but presents challenges installing a CPanel managed server.

The Solution:
Compile APC from source using the latest stable version http://pecl.php.net/get/APC-3.0.19.tgz

Instructions

cd /usr/local/src && wget http://pecl.php.net/get/APC-3.0.19.tgz && tar -xzf APC-3.0.19.tgz && cd APC-3.0.19

Now you will have APC downloaded untarred and you will be in the configure directory.

phpize && ./configure --enable-apc --enable-apc-mmap --with-apxs=/usr/local/apache/bin/apxs --with-php-config=/usr/local/bin/php-config && make && make install

This will configure APC and install it in your extension directory. no-debug-non-zts-20090626 will be the name of the extension directory if your running PHP 5.3. If you are running PHP 5.2 your extension directory will be no-debug-non-zts-20060613

cd /usr/local/lib/php/extensions/no-debug-non-zts-20090626
dir

You should see a file named apc.so in that directory

If there are no errors listed and apc.so exist in the right directory then nano /usr/local/lib/php.ini
you should see extension=apc.so somewhere. If not add it then copy the settings from wp-content/plugins/w3-total-cache/ini/apc.ini and add them below extension=apc.so control x and save php.ini then service httpd restart

php -r 'phpinfo();' | grep 'apc'

If you get output from that last command then it is installed and working and you can go to one of your web pages and make sure it loads.

Adding the APC GUI
To be able to view your APC caching statistics move the the apc.php file from /usr/local/src/APC-3.0.10/acp.php to somewhere in your /public_html and you can access it from a browser.
You will need to set an admin username and password to the apc.php script which can be done by opening the file in an editor and replacing the default username and password at the top of the script

Another good resource for installing APC on a WHM/Cpanel server can be found at http://www.brettbrewer.com/index2.php?option=com_content&do_pdf=1&id=70

Tagged as:

Leave a Response