Did You Know?
Donate to TecMint

LFCS - Linux Foundation Certified SysAdmin - Exam Preparation Guide

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

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

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
/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.


// Show all information, defaults to INFO_ALL


Open any browser and type the following URL. You will see APC enabled configuration similar to below.

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.


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

Ravi Saive

Owner at TecMint.com
Simple Word 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.

Your name can also be listed here. Work as a Paid freelancer/writer at TecMint.
Download Free eBooks
Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

20 Responses

  1. Mahieddine says:

    Thank you man :)

  2. Zoplor says:

    Good, I find this article on Google,It better than Chinese’s article,Best regards

  3. Thanks for the tutorial. Saved me some time.

  4. Gabriel says:

    Thank you. I just installed it on my CentOS 5.x system as instructed. No errors.

  5. Recron says:


    I have installed APC on CentOS6.4 64Bit. I am using WHM. Everything went fine and APC shows as enabled in phpinfo. Then I moved the file from /usr/local/lib/php/apc.php to /home/domain.com/.

    However, for some reasons I am unable to run domain.com/apc.php
    It throws back the 500 Internal Server Error.

    Any suggestions? Like .HTACCESS or Apache config file? or some settings in APC.php or PHP.INI?

    Thanks in advance.

    • Daniel says:

      Hi, I think the 500 error is apache “deny from all” directive somewhere :)
      (probably in /etc/httpd/conf/httpd.conf or something.. maybe also in “conf.d/” there, like if you install phpMyAdmin, it gives you 500 error on “site.com/phpmyadmin” until you configure /etc/httpd/conf.d/phpmyadmin.conf (sorry if i confuse a little bit names and path, im not good remembering this, i often use ‘find / -name myfilename’ myself :D ) )

      so you need to go through apache config files I think and find where you can give permission to ‘all’ to access this path on your server.

      if you have “allowoverride all” at least, so you can use .htaccess in root of your website to allow access to certain path.

      hope it helps :) and hope i didnt confuse anyone, coz im still learning linux myself :) not a pro.

  6. Daniel says:

    What is the difference between Xcache and this one? can I install both of them on same server? (one optimizes what it can while other optimizes the rest :D )

    Thanks :) . The article is very useful.

  7. Matt says:

    can’t uninstall get: pecl/apc not installed

    Any ideas?

    I’m trying to downgrade from 13 to 9

  8. Antonio says:

    Thanks alot mate!! Perfect!!

  9. Velichko Taleff says:

    Thank you! Very well written and explained!

  10. katal2hod says:

    Do you have tutorial for installing PECL uploadprogress library in centos 6.5?

    Thanks :)

  11. Hello!

    OK! APC is installed and I can view the Statistics.

    And now, how APC will cache my PHP sites?

    The APC is not creating /etc/apc.* files.

    The statistics is displaying NO PHP FILES cached.

    Thanks a lot. I want to understand how APC works.

  12. IPC Oye says:

    @Andre Luis de Andrade:
    APC works by storing the compiled bytecode of your PHP script on the memory, so next time when a request for the same page appears, APC will provide the cached code instead of re-read and recompile the code again from your disk, thus increasing the load speed.

  13. IPC Oye says:

    First, make sure you already have these things installed on your Centos:
    make, gcc, php-devel, php-pear.
    And then, type “pecl install uploadprogress”
    You should see something like this after the installation has finished:
    Build process completed successfully
    Installing ‘/usr/lib64/php/modules/uploadprogress.so’
    install ok: channel://pecl.php.net/uploadprogress-

    Note that I’m using Centos 64 bit, if you’re using 32 bit, then the path will show
    Installing ‘/usr/lib/php/modules/uploadprogress.so’

    Then, use “vi /etc/php.ini” (or Nano, or VIM)
    Add this line on the bottom:
    Save and close, then restart your Apache by using service httpd restart
    Done ;)

  14. Satya says:

    Hi ravi,

    I am having some problem with APC working properly. File cache always shows Hits = 1 and misses keep increasing, but at the same time, the cached file entries show some numbers in hundreds over some time.

    User cache entries shows to be working normally it seems.

    But almost twice a day i keep getting Internal server error and then have to restar php-fpm.

    I hv allocated 1024M memory and some other regular config stuff.

    If you have more idea, can i have your email ID to discuss this and send you more details about it.

    Warm rgds

  15. Sami says:

    Thakns for this nice tutorial.
    APC is now installed but it seems not to work : the uptime value is always 0, so I think APC is not working ! How can I check if it really caches my magento site ?
    Regards :)

  16. John says:

    Installed with no problems. Thanks

  17. Guillermo says:

    Excellent thank you

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.