Install APC for PHP

Of note, APC has been discontinued. Instead, check out the NGINX Cache Manager for your PHP caching needs.

In this guide I’ll cover how to install APC for PHP which is the Alternative PHP Cache that can help speed up your PHP powered website. You can read our speed up PHP with APC guide for more info on how APC works.

After you install APC, you will want to learn how to view and clear the APC cache. That way you can keep tabs on what APC is caching, and how effective it might be working for your website.

Installing APC for PHP

You’ll need to have root access on either a VPS or dedicated server in order to install APC for PHP. You also will need to be running either the FastCGI or DSO PHP handlers for APC to function properly.

  1. Login to your server via SSH with your root SSH access.
  2. Change directories with the following command:

    cd /usr/local/src

  3. Get the source code for APC with the following code:

    wget https://pecl.php.net/get/APC-3.1.13.tgz

  4. Now extract the APC archive with this command:

    tar xvzf APC-3.1.13.tgz

  5. Navigate into the extracted folder:

    cd APC-3.1.13

  6. Now run the following command to configure APC to your PHP environment:

    phpize

    You should get something like this back:

    Configuring for:
    PHP Api Version: 20090626
    Zend Module Api No: 20090626
    Zend Extension Api No: 220090626

  7. Next configure the source code to run on your server with this command:

    ./configure

    You’ll see a lot of text scrolling by looking like this:

    checking for grep that handles long lines and -e… /bin/grep
    checking for egrep… /bin/grep -E
    checking for a sed that does not truncate output… /bin/sed
    checking for cc… cc
    ……….
    creating libtool
    appending configuration tag “CXX” to libtool
    configure: creating ./config.status
    config.status: creating config.h

  8. Now you’ll want to actually create the APC software with this command:

    make

    Again you’ll see a lot of text scrolling by looking like:

    /bin/sh /usr/local/src/APC-3.1.13/libtool –mode=compile cc -I. -I/usr/local/src/APC-3.1.13 -DPHP_ATOM_INC -I/usr/local/src/APC-3.1.13/include -I/usr/local/src/APC-3.1.13/main -I/usr/local/src/APC-3.1.13 -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/APC-3.1.13/apc.c -o apc.lo mkdir .libs
    ………
    ———————————————————————-
    Libraries have been installed in:
    /usr/local/src/APC-3.1.13/modules
    Build complete.

  9. Locate the extension_dir for PHP with this command:

    grep extension_dir /usr/local/lib/php.ini

    You should get back a path that looks something like:

    extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20090626”

  10. Run this command to copy the APC Apache module (apc.so) to your PHP extension directory:

    cp -frp modules/apc.so /usr/local/lib/php/extensions/no-debug-non-zts-20090626/

  11. Edit your php.ini file with your favorite text editor after making a backup:

    cp -frp /usr/local/lib/php.ini /usr/local/lib/php.ini-BAK
    vi /usr/local/lib/php.ini

    Add these APC settings to the very bottom and save the php.ini file:

    extension=apc.so
    apc.enabled=1
    apc.shm_size=128
    apc.cache_by_default=”1″
    apc.shm_segments=”1″
    apc.ttl=”7200″
    apc.user_ttl=”7200″
    apc.gc_ttl=”1800″
    apc.optimization = 0
    apc.num_files_hint=”1024″
    apc.use_request_time = 1
    apc.mmap_file_mask=”/tmp/apc.XXXXXX”
    apc.enable_cli=”0″
    apc.slam_defense=”0″
    apc.file_update_protection=”2″
    apc.max_file_size=”1M”
    apc.stat=”1″
    apc.write_lock=”1″
    apc.report_autofilter=”0″
    apc.include_once_override=”0″
    apc.rfc1867=”0″
    apc.rfc1867_prefix=”upload_”
    apc.rfc1867_name=”APC_UPLOAD_PROGRESS”
    apc.rfc1867_freq=”0″
    apc.localcache=”0″
    apc.localcache.size=”512″
    apc.coredump_unmap=”0″

  12. Place the following code inside a info.php script on your site:

    <?php
    phpinfo();
    ?>

  13. Access that script on your site such as https://example.com/info.php. Look for the apc section: apc enabled in phpinfo

    If you don’t see an apc section yet you might need to restart Apache with this command:

    service httpd restart

Congratulations! You should now have successfully installed APC for PHP!

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

19 thoughts on “Install APC for PHP

  1. I think this article should be updated. I tried following these directions to install APC but kept getting an error (make: *** [apc_cache.lo] Error 1). After some research, I read that APC isn’t really compatable with PHP 5.5+ and OPCache should be used instead. On my new VPS, I had PHP 5.6 installed by default, so it’s kind of confusing. Maybe you should put a note at the top of this article to say that you need a specific PHP version and the process will fail with anything hihger than 5.5?

    1. This article is great and your resources in general good but it had me confused for awhile too. Would be great to notify at the top like Mitchell said. I discovered the same in my research and ended up enabling OPCache instead since the dedicated server with you guys has a newer PHP version. I think an article on step by step how to enable OPCache and a link at the top of this one pointing to it would be great for the community. I ended up having to use your resources and some via Google to figure out how to get OpCache running.

  2. I´m having an error, says:

     

    Resolving pecl.php.net… 104.236.228.160

    Connecting to pecl.php.net|104.236.228.160|:80… connected.

    HTTP request sent, awaiting response… 200 OK

    Length: 171591 (168K) [application/octet-stream]

     

    APC-3.1.13.tgz: Permission denied

    1. Hi Elihu, did you know about PHP OpCache? It is basically the replacement for APC, which is not being updated anymore I believe. PHP OpCache is a default in the newer version of PHP which dedicated and virtual servers typically include. I’m not sure about the shared servers as I never used them, however, i installed opcache on my dedicated and virtual server here at inmotionhosting and it works great on both. Nice speed boost. Did a lot of digging around when Google said they are factoring pagespeed and I ended up using opcache along with other caching stuff and it improved my site’s load time by like 3 times. I found instructions on inmotionhosting to install opcache and a web resource via google to get it working perfectly. I tried to do APC awhile back and it just never worked for some reason. Good luck.

  3. I followed all steps carefully, but at last I don’t see APC in phpinfo. Can you please check what is wrong with it.

     

    Thanks

    1. I have followed all the steps carefully and I didn’t get any error. But when I see the phpinfo it don’t show APC there. Can you please check what I did wrong.

    2. This works for us on our test servers. You may want to submit a ticket to Live Support to see if they can tell why it is not showing up in the php.ini for you.

  4. I ammended this code to the bottom of the php.ini file

    extension=apc.so

    apc.enabled=1

    apc.shm_size=128

    apc.cache_by_default=”1″

    apc.shm_segments=”1″

    apc.ttl=”7200″

    apc.user_ttl=”7200″

    apc.gc_ttl=”1800″

    apc.optimization = 0

    apc.num_files_hint=”1024″

    apc.use_request_time = 1

    apc.mmap_file_mask=”/tmp/apc.XXXXXX”

    apc.enable_cli=”0″

    apc.slam_defense=”0″

    apc.file_update_protection=”2″

    apc.max_file_size=”1M”

    apc.stat=”1″

    apc.write_lock=”1″

    apc.report_autofilter=”0″

    apc.include_once_override=”0″

    apc.rfc1867=”0″

    apc.rfc1867_prefix=”upload_”

    apc.rfc1867_name=”APC_UPLOAD_PROGRESS”

    apc.rfc1867_freq=”0″

    apc.localcache=”0″

    apc.localcache.size=”512″

    apc.coredump_unmap=”0″

    1. Hello Jake,

      Thanks for including your code. It does appear to be correct, but the only thing that appears to be amiss may be that you’re missing quotes around “apc.so”.

      It should look like this:

      extension=”apc.so”

      Please try making that change and let us know if you continue to have any further problems.

      Kindest regards,
      Arnel C.

  5. I am also having an issue, I have went through the steps twice and am sure I followed every step yet APC is not shown in info.php

  6. Hi Arnel, 

    There were no errors during the instllation process, however, after running the final command to restart apache, it did not show that APC was installed when I checked the info.php file. It does appear I meet the requirements for I am on a VPS-1000S plan with root access, and according to info.php, I am runing CGI/FastCGI. I spoke to someone on support and for some reason they told me I had to disable FastCGI so now I’m even more confused. It appears the person I had spoken to who told me to disable FastCGI was not familar with APC for acccording to this doc, I need FastCGI.

    UPDATE: I just removed and went through the steps again and it appears to be working now. Not sure why it wasn’t before, possible that I missed a step during installation. Apreciate the lightning quick followup Arnel! 

    Best Regards,

    mark

    1. Hello Mark, I just saw your reply after I posted mine. Glad it’s all working! No worries, about the steps – these things can be tedious and easy to miss. Hope all is well!

      Have a great day!
      Arnel C.

    2. Hello Mark,

      Thanks for the reply and apologies for the confusion with the support tech. I was about to write a ticket to have APC installed on your server, but I decided to double-check the info.php. When I did, I found that APC is already installed and that FASTCGI is setup on your server. If you ran the info.php screen on your server BEFORE the installation, it’s always possible that the browser cached the page. Make sure to clear your browser cache. I ran a search for APC, and then double-checked the listed server configuration for FCGI.

      If you continue to have problems with the installation (or you don’t see it), provide a URL that you’re using and we can look further into the matter.

      I hope this issue is closed and everything is okay. Please let us know if you require any further assistance.

      Regards,
      Arnel C.

  7. Hi Arnel, 

    There were no errors during the instllation process, however, after running the final command to restart apache, it did not show that APC was installed when I checked the info.php file. It does appear I meet the requirements for I am on a VPS-1000S plan with root access, and according to info.php, I am runing CGI/FastCGI. I spoke to someone on support and for some reason they told me I had to disable FastCGI so now I’m even more confused. Is there anyway one of your technical support people who is familar with APC can install it on my VPS? It appears the person I had spoken to who told me to disable FastCGI was not familar with APC for acccording to this doc, I need FastCGI.

    Thanks,

    mark

  8. Unfortanately this did not work. I thought it would be as simple as following the directions (which I did) but it did not. This guide should probably be updated for I’m guessing it is either out of date or not compatible with your current VPS deployments which likely run newer versions of PHP, etc.

    1. Hello Mark,

      I’m sorry that you had problems running the instructions above. However, we would need more information from you in order to determine why the instructions do not work. Did you meet the requirements stated at the beginning of the instructions (You’ll need to have root access on either a VPS or dedicated server in order to install APC for PHP. You also will need to be running either the FastCGI or DSO PHP handlers for APC to function properly.) ? If you are a customer, can you please provide us account information so that we know what type of server was involved?

      Did you receive any particular errors? Where did the installation fail? Please provide us with this information so that we can determine where the instructions have failed. This article is considered up-to-date at this point of time and we need to be able verify that a problem has occurred before. This is needed because anyone can comment on these pages and simply say it didn’t work. Help us keep it up-to-date by indicating where a problem has occurred.

      We appreciate your patience and understanding in helping us keep these documents as accurate an up-to-date as possible.

      Regards,
      Arnel C.

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+