Install APC (Alternative PHP Cache) in RHEL/CentOS 6/5 & Fedora 20-12

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.

Install PHP APC in Linux

Install and Enable PHP APC in Linux

The instructions provided here shows how to install and enable APC caching for PHP on RHEL 6.5/6.4/6.3/6.2/6.1/6/5.8/5.6, CentOS 6.5/6.4/6.3/6.2/6.1/6/5.8/5.6 and Fedora 20,19,18,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.

http://localhost/phpinfo.php
PHP APC Extension

PHP APC Configuration Screen

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.

http://localhost/apc.php

Some screenshots of APC Administration panel for your reference.

Vies Host Stats
APC View Host Stats

APC View Host Stats Overview

System Cache Entries
APC System Cache Entries

APC System Cache Entries Overview

User Cache Entries
APC User Cache Entries

APC User Cache Entries Overview

APC Login Screen
APC Admin Login

APC Admin Login Screen

APC Version Check
APC Version Check

APC Version Check Overview

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
Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

29 Responses

  1. James says:

    Hi Ravi. Thanks for publishing this. I was able to use your instructions to install APC on my server’s default PHP version without a problem. However, I’m running a few other versions of PHP on the same server, and I’d like to use it on one of those, specifically PHP 5.6.35.

    I installed that with Plesk and the path to the php.d directory is /opt/plesk/php/5.6/etc/php.d. I tried placing the apc.ini file there, but that didn’t work. I also tried adding the directive “extension=apc.so” directly to that PHPs php.ini file. It’s still not running.

    Do you have any advice to get this working?

    • Ravi Saive says:

      @James,

      I suggest you to compile APC for your PHP 5.6 version to /opt/plesk/php/5.6/etc/php.d directory.. This is the only solution, I think.

  2. Mary Rax says:

    Hello,

    I am working on one of my client’s project scislides.com which loads up very very slowly. I was going through the possible fix and came across below one but not sure whether this would work or not. Can somebody help?

    How to fix – Page Cache Test (Server Side Caching)

    In order to pass this test, you are advised to use a caching mechanism for your pages. There are three methods which can be used to caching your web pages:

    Alternative PHP caching
    – Alternative PHP Cache (APC) is an open source framework which caches data using intermediate PHP code. Most web programmers who are familiar with the PHP programming language can easily set up Alternative
    PHP Cache for your site.
    Quickcache
    – Quickcache is a lightweight page caching solution which was formerly known as jpcache. Quickcache caches the page output rather than compiling the PHP page, making it a superior version of page caching to the Alternative PHP caching. Quickcache can be quickly downloaded from their website and can reduce your page load time up to 80%.
    WP Super Cache
    – If you have a WordPress website, WP Super Cache can be installed within seconds and without no programming knowledge.

    Regards
    Mary Rax

  3. Maxczysto says:

    Good Tutorial, installed with no problems. Thanks for Share

  4. alessandro says:

    where can I find the version 3.1.15-dev to Centos?
    thank you
    Best regards

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.