Search For Answers
APC for cPanel
Last updated: June 20, 2011
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.
Supported only when running in a persistent (DSO/FCGID) manner and not suPHP.
root@example [/]# /usr/local/cpanel/bin/rebuild_phpconf --current
Available handlers: dso cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: dso
SUEXEC: enabled
Installation
root@example [~]# yum install pcre-devel -y
root@example [~]# pecl install apc
Once installed you should see similar to the following:
Build process completed successfully
Installing '/usr/include/php/ext/apc/apc_serializer.h'
Installing '/usr/lib/php/extensions/no-debug-non-zts-20060613/apc.so'
install ok: channel://pecl.php.net/APC-3.1.9
Extension apc enabled in php.ini
NOTE: Make sure it was installed in the correct location.
root@example [~]# grep extension /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
In this example "apc.so" was installed to '/usr/lib/php/extensions/' whereas going by your php.ini's extension_dir it should be in '/usr/local/lib/php/extensions/' (missing /local/ in the path) and will need to be copied over accordingly.
To identify the location of your php configuration:
root@example [~]# php -i |grep php.ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
If not installed to the correct location, then copy "apc.so" to the correct location.
root@example [~]# cd /usr/lib/php/extensions/no-debug-non-zts-20060613/
root@example [/usr/lib/php/extensions/no-debug-non-zts-20060613]# cp apc.so /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
Make sure apc is enabled. If so confirm apahe is happy and then restart for changes to take affect.
root@example [~]# grep apc /usr/local/lib/php.ini
extension="apc.so"
root@example [~]# apachectl configtest
Syntax OK
root@example [~] service httpd restart
Configuration
Fine tuning for a production environment.
; Example APC Configuration
extension="apc.so"
apc.ttl=0
apc.stat=0
apc.shm_size=96M
apc.cache_by_default=0
apc.filters="+public_html"
Save your changes to the php.ini file and restart apache for changes to take affect.
Please see http://php.net/manual/en/apc.configuration.php for clarification on these parameters.
Monitoring APC
The following script "apc.php" is bundled with APC and can be copied to a docroot then viewed through a browser and it will provide a detailed analysis of the internal workings of APC.
root@example [~]# locate apc.php
root@example [~]# cd /usr ; find * |grep apc.php
NOTE: It may also be advised to copy the script to a password protected sub-directory.
To gain admin access the user/pass will need to be defined in the header of the script. If left by default the feature will be disabled.
defaults('ADMIN_USERNAME','apc');
defaults('ADMIN_PASSWORD','password');