APC (Alternate PHP Cache) is an free and open source cache for PHP code. The main goal of this module is to provide robust framework for caching and optimizing PHP code.
The instructions provided here shows how to install and enable APC caching for PHP on RHEL 6.3/6.2/6.1/6/5.8/5.6, CentOS 6.3/6.2/6.1/6/5.8/5.6 and Fedora 17,16,15,14,13,12 using PECL command to download from the repositories.
Install Dependency Packages for APC
First, we need to install required packages called pecl, phpize and apxs commands, to install APC using YUM package manager tool.
yum install php-pear php-devel httpd-devel pcre-devel gcc make
Install APC Using PECL
Now we have all the needed packages to install APC. Here we use PECL command to install it. Please select default settings when asked.
pecl install apc
Sample Output :
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update downloading APC-3.1.9.tgz ... Starting to download APC-3.1.9.tgz (155,540 bytes) .................................done: 155,540 bytes 54 source files, building running: phpize Configuring for: PHP Api Version: 20090626 Zend Module Api No: 20090626 Zend Extension Api No: 220090626 config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, ...): suspicious cache-id, must contain _cv_ to be cached ../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from... config.m4:180: the top level config.m4:180: warning: AC_CACHE_VAL(PHP_APC_GCC_ATOMICS, ...): suspicious cache-id, must contain _cv_ to be cached ../../lib/autoconf/general.m4:1974: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:1994: AC_CACHE_CHECK is expanded from... config.m4:180: the top level 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] :
Enable APC PHP Extension
Run the following command to enable APC extension in Apache configuration.
echo "extension=apc.so" > /etc/php.d/apc.ini
Restart Apache Service for APC
Restart the Apache service to take new changes.
service httpd restart OR /etc/init.d/httpd restart
Verify APC Installation
Create a file phpinfo.php in Apache web root directory. For example /var/www/html/phpinfo.php.
# vi /var/www/html/phpinfo.php
Add the following code to it. save and close.
<?php // Show all information, defaults to INFO_ALL phpinfo(); ?>
Open any browser and type the following URL. You will see APC enabled configuration similar to below.
Enable PHP APC administration
To enable APC administration panel, copy the following file.
cp /usr/share/pear/apc.php /var/www/html/
Now open the file apc.php with VI editor.
# vi /var/www/html/apc.php
Now set the username and password in the file apc.php as shown below.
defaults('ADMIN_USERNAME','apc'); // Admin Username defaults('ADMIN_PASSWORD','Set-Password-Here'); // Admin Password - CHANGE THIS TO ENABLE!!!
Type the following URL in the browser. You will get administration panel of APC.
Some screenshots of APC Administration panel for your reference.
Vies Host Stats
System Cache Entries
User Cache Entries
APC Login Screen
APC Version Check
Upgrade APC using PECL
To upgrade, just execute following command it will download and upgrade APC.
pecl upgrade apc
Uninstall APC using PECL
If you like to remove it, then simple type the following command to uninstall APC completely from the system.
pecl uninstall apc