APC Info Page

How to Install APC (Alternative PHP Cache) on CentOS 5.6 46

There’s a lot of conflicting information out there on how to install the APC opcode cache on a CentOS 5.6 box. Here’s how I did it:

This tutorial assumes you’re running CentOS 5.6 on a dedicated server, and that you have superuser (root) access. These instructions may also worked in a VPS or shared hosting environment, but if you run into trouble, you should contact your provider’s tech support to see if they have any alternative steps you should take.

First, you need to make sure the following packages are installed:

yum install php-devel pcre-devel

Because you’re going to be compiling a package, you’ll need a C compiler (like gcc) and make. The easiest way to install all the right development tools is with:

yum groupinstall "Development Tools"

Be sure to include those quotes.

Now you’re ready to download and untar the package:

cd /usr/local/src
wget http://pecl.php.net/get/APC-3.1.9.tgz
tar -zxvf APC-3.1.9.tgz

Now it’s time to set it up!

cd APC-3.1.9
whereis php-config

Take note of where php-config is located (it’s usually in /usr/bin/php-config) as you’ll need it in the next step. If it’s in a different location, use that for the php-config path below:

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

Next, if you have an /etc/php.d/ directory on your server, create a file called /etc/php.d/apc.ini to store all your configuration settings (if it already exists, you can just edit the existing one). If you don’t have an /etc/php.d/ directory, you can add these configuration settings to your existing php.ini file, which is usually located at /etc/php.ini.

Here’s an example of my apc.ini file, with lots of comments for some guidance. This is a pretty straightforward configuration, so feel free to copy and paste:

; Enable the extension module
extension = apc.so

; Options for the APC module version >= 3.1.3
; See http://www.php.net/manual/en/apc.configuration.php

; This can be set to 0 to disable APC.
; The number of shared memory segments to allocate for the compiler cache.
; The size of each shared memory segment, with M/G suffixe
; A "hint" about the number of distinct source files that will be included or
; requested on your web server. Set to zero or omit if you're not sure;
; Just like num_files_hint, a "hint" about the number of distinct user cache
; variables to store.  Set to zero or omit if you're not sure;
; The number of seconds a cache entry is allowed to idle in a slot in case this
; cache entry slot is needed by another entry.
; use the SAPI request start time for TTL
; The number of seconds a user cache entry is allowed to idle in a slot in case
; this cache entry slot is needed by another entry.
; The number of seconds that a cache entry may remain on the garbage-collection list.
; On by default, but can be set to off and used in conjunction with positive
; apc.filters so that files are only cached if matched by a positive filter.
; A comma-separated list of POSIX extended regular expressions.
; The mktemp-style file_mask to pass to the mmap module
; This file_update_protection setting puts a delay on caching brand new files.
; Setting this enables APC for the CLI version of PHP (Mostly for testing and debugging).
; Prevents large files from being cached
; Whether to stat the main script file and the fullpath includes.
; Vertification with ctime will avoid problems caused by programs such as svn or rsync by making
; sure inodes havn't changed since the last stat. APC will normally only check mtime.
; Whether to canonicalize paths in stat=0 mode or fall back to stat behaviour
; With write_lock enabled, only one process at a time will try to compile an
; uncached script while the other processes will run uncached
; Logs any scripts that were automatically excluded from being cached due to early/late binding issues.
;This setting is deprecated, and replaced with apc.write_lock, so let's set it to zero.

The final step is to restart Apache with either:

service httpd restart


apachectl restart

To make sure APC is running, create a php file somewhere in your web root that simply contains:

then load the file and scroll down to the APC section to verify that it’s enabled.

For some cool statistics, copy the usr/local/src/APC-3.1.9/apc.php file somewhere in your web root, and then open it in your browser. Edit the file on the server if you’d like to add a password and enable login to see more details. Here’s a peek at what it looks like:

APC Info Page

Congratulations! You’ve just installed APC on CentOS 5.6!

Further Reading

  • brad

    I don’t have /etc/php.d/apc.ini and nano won’t let me create it. what should i do?

    • The only reasons I can think that nano won’t let you create it is because either 1) you’re in a shared hosting environment, or 2) you’re not the superuser (root) when you try to create apc.ini. If shared hosting, which one are you using? If it’s the root issue, just su root and give it a shot.

      • brad

        VPS logged in as root. i don’t have a php.d directory.
        does that mean that php-devel didn’t install?

        • If you have a php.ini file (generally in your web root directory in a shared hosting or VPS environment), you can also add the configuration options in there. I’ve updated the blog post to mention that.

  • Steve, nice tutorial. I have reimaged my server 4 times trying to get this right. Running centos 5.5 with plesk. I got down to the .config/ line and got this:
    php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
    [[email protected] APC-3.1.9]# ./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/bin/php-config
    checking for egrep… grep -E
    checking for a sed that does not truncate output… /bin/sed
    checking for gcc… no
    checking for cc… no
    checking for cc… no
    checking for cl… no
    configure: error: no acceptable C compiler found in $PATH
    See `config.log’ for more details.
    [[email protected] APC-3.1.9]#

    Also I have no make? Can you tell me how to install “make” ?

    Thanks, TD

    • Ahh…. it looks like you don’t have a C compiler. I recommend gcc. Do this to install it:

      yum groupinstall “Development Tools”

      Be sure to include the quotes. That should install everything you’re missing! I’ll add this step to the article.

  • Excellent article! I followed every step here and finished it with no problems! 🙂

    I just have one question, i moved that apc.php to our ‘main’ domain so i have only one entry place for apc statistics, so the question is: do i need to copy apc.php to every domain in order or is only one copy of apc.php enough to see statistics across entire server?


  • Hmm ok i just added apc.php to another domain which has much
    more traffic and I’m seeing different stats. So i guess this does need to be added per domain?

    Sorry for maybe dumb question. 🙂

    • That’s interesting. As I understand it, you’ll see stats per cache, so you should see the entire server’s stats in one spot. Maybe stuff is just expiring quickly? Try loading both apc.php files side-by-side and see if there are major diffs.

  • Well take a look your self:

    (removed for security)

    Both domains are on same server.

    I’ll leave these files on with no authentication for next 10-12h or until your next comment. Second site has barely any traffic atm.

    • Well, yep! Looks like two separate 64M caches. Do your vhosts all share a single php.ini file? You may want to do some Googling about optimizing APC with virtual hosts. You may be able to get away with a smaller cache on your “quieter” site.

  • Hmm well then that means i have 64M for every domain i have on server(11 at the moment)?

    I disabled APC at the moment and i will google regarding this issue and also i will contact my hosting support to see if they can help me with this.

  • Rik

    Thanks man, great help!

  • Mathiau


    found this

    yum install pcre-devel

    and it now looks like it worked, not a single guide mentioned pcre-devel 🙂

    • Well then I’m glad you stumbled on to mine. Glad you got it working. 🙂

  • Mathiau

    def bookmarking your site!

  • roberto

    I tried to install apc but i got this

    ./configure is not a file o directory

    any help?

    • Looks like maybe you forgot to cd into the directory where you untarred APC?

      • roberto

        im into /usr/bin/
        and then run ./configure and get the message

        • Ah… please carefully re-read the part right after “Now it’s time to set it up!” You don’t ever need to be in the /usr/bin directory, you simply need to reference that directory in the ./configure statement. Follow the instructions exactly as written, and you should be fine. 🙂

          • roberto

            i repeated the steps and got this

            [email protected] [/usr/local/src]# phpize
            Cannot find config.m4.
            Make sure that you run ‘/usr/local/bin/phpize’ in the top level source directory of the module

          • roberto

            I have centos 5.7 i dont know if this helps you. I tried for days. PHPINFO says its enabled but when i try to use apc.php top see teh report I got
            Internal Server Error

            The server encountered an internal error or misconfiguration and was unable to complete your request.

            Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

            More information about this error may be available in the server error log.

            Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

          • And what happened when you Googled “phpize Cannot find config.m4” ? 🙂


            phpize needs to be run inside the /usr/local/src/APC-3.1.9 directory… just like it says in the instructions. 🙂

  • roberto

    Finally its installed, and I can see the graphic open apc.php but I think its not woring because the only file is cached is apc.php no other file is cached

  • Pingback: How to Install APC Alternative PHP Cache on CentOS 5.6 | Steve Jenkins Blog « myiphonenotes()

  • Jack

    Hi, I got apc.so in modules and added the apc.ini in php.d folder but didn’t work with my apache server, do you know why?
    Thank you!

    • jack

      it works, apache load the apc.so in different folder.

  • Sometimes, once in a while I stumble upon blogs like this…first I read this post (of course my problem was solved after reading this) but I wanted to know more about you… coz somewhere I already knew that u have to be someone different from others… so I read ur bio n my guess was right… u r the man….keep it up Steve..am only 25 yrs at present I might never get chance to meet u but I will always pray for you and your family…am subscribing to your blog…love…

  • hello friend,
    i’m here by looking for how we install apc on linux.
    as im a newbie for linux administration, sometime i will meet an error or crash my site. I hope you can include tutorial how i gonna totally uninstall APC in case after installation my site not working well.
    thank you.

  • @garaa what problem u facing few days ago I successfully installed APC on linux centos 5.7

  • Hi thank you for your great steps in how to install APC, I get to point phpize command no issue, but when I type in phpize in the terminal I get command not found, so I don’t get the ability to continue, what could be wrong, I am on Plesk 10, and php 5.3.3.
    Please help me, I am stuck badly

  • Dear Steve,
    thanks a lot for the HowTo. At the moment I can not really guess the efficiency of APC, but installation instruction works great!
    Thank you!
    Best regards

  • bill

    Thanks Steve, It is a rarity that instructions work as advertised but your did with no problems.

    Thanks again

  • Sergey

    apc.php is not located anywhere on my Debian 6.04 after APC installation. Any idea where to get it?

  • Hi Steve,
    I followed the steps and done evrything in it. Everything went right but now when I added the phpinfo file, there is no section about apc.

    Any idea ?

    Thank you

  • Andy

    Don’t work

    All I get in my log is….

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/extensions/no-debug-non-zts-20060613/apc.so’ – /usr/local/lib/php/extensions/no-debug-non-zts-20060613/apc.so: cannot open shared object file: No such file or directory in Unknown on line 0

  • Very good tutorial, now my site is using apc and I’m happy.

  • Geo

    Thanks Man,

    very clear

  • Awesome post – worked perfectly after many failed attempts. Much appreciated!

    • Thanks – glad you got it working! Although, I’m hoping that the “many failed attempts” were while trying some other documentation, instead of this one! 🙂

  • Indeed they were! Yours was spot on!


  • uzi

    Worked like a charm minus the httpd restart (/etc/init.d/httpd restart graceful) in my case!


  • Pingback: Error installing apc for php on linux/centos()

  • Every time I enable this it crashes my site with a no response error.

    APC Support disabled
    Version 3.1.9
    APC Debugging Disabled
    MMAP Support Enabled
    MMAP File Mask no value
    Locking type pthread mutex Locks
    Serialization Support broken
    Revision $Revision: 308812 $
    Build Date Mar 25 2013 11:59:36

  • When I check my /var/log/httpd/error_log :

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php-zts/modules/apc.so’ – /usr/lib/php-zts/modules/apc.so: undefined symbol: sapi_globals in Unknown on line 0