The Perfect APC Configuration

Here was my setup on an Amazon Medium Instance using APC:

php.ini configuration

[APC]
extension=apc.so
apc.enabled=1
apc.shm_segments=1

;32M per WordPress install
apc.shm_size=128M

;Relative to the number of cached files (you may need to watch your stats for a day or two to find out a good number)
apc.num_files_hint=7000

;Relative to the size of WordPress
apc.user_entries_hint=4096

;The number of seconds a cache entry is allowed to idle in a slot before APC dumps the cache
apc.ttl=7200
apc.user_ttl=7200
apc.gc_ttl=3600

;Setting this to 0 will give you the best performance, as APC will
;not have to check the IO for changes. However, you must clear 
;the APC cache to recompile already cached files. If you are still
;developing, updating your site daily in WP-ADMIN, and running W3TC
;set this to 1
apc.stat=1

;This MUST be 0, WP can have errors otherwise!
apc.include_once_override=0

;Only set to 1 while debugging
apc.enable_cli=0

;Allow 2 seconds after a file is created before it is cached to prevent users from seeing half-written/weird pages
apc.file_update_protection=2

;Leave at 2M or lower. WordPress does't have any file sizes close to 2M
apc.max_file_size=2M

;Ignore files
apc.filters = "/var/www/apc.php"

apc.cache_by_default=1
apc.use_request_time=1
apc.slam_defense=0
apc.mmap_file_mask=/var/www/temp/apc.XXXXXX
apc.stat_ctime=0
apc.canonicalize=1
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.lazy_classes=0
apc.lazy_functions=0

While this configuration works great for me, it may not for you. Finding “The Perfect APC Configuration” is like asking how many stars are in the sky. The are endless variables, like, “How much RAM, how many websites, do your websites support lazy classes, etc…” The best way to create your config is to do a little research. This post was meant to give you a push in the right direction.

P.S. There seems to be a lot of debate about apc.stat = 0. The general thought is, set apc.stat=0 on production servers and it will prevent APC from actually going to the IO to check if the file has been changed. However, the WordPress dashboard and W3TC get kinda bitchy with this setting!

My advice: Are working in the WordPress dashboard daily, and running W3TC? Then set: apc.stat = 1. Your fragmentation will be higher. Your sites will load slightly slower, but when you click Update Post, APC will flush that piece of cache.

UPDATE 2013.08.01

PHP 5.5+ is out (and APC is deprecated) and with it comes the new OPcache.

About Greg Rickaby

Director of Engineering @WebDevStudios / Author & Tech Editor @ForDummies / @WordPress Contributor / @gatsbyjs Maintainer / Follow Greg on Twitter

19 Comments

  1. Peter Einstein on June 27, 2013 at 9:18 am

    Good Job!
    Handling more than 1500 online together without any problem.

  2. How To: Install LAMP on Ubuntu - Greg Rickaby on August 12, 2013 at 7:03 am

    […] APC is the de-facto in PHP acceleration. It’s a PHP opcode cacher and works by caching PHP objects, functions, and database queries into your server’s RAM. If you run a WordPress web site – then it takes full advantage of APC out-of-the-box. See my post on The Perfect APC Configuration […]

  3. Oğuz Kağan Aslan on October 13, 2013 at 8:39 am

    APC uses less memory than Opcache, this means “long live APC” 🙂

  4. John on October 22, 2013 at 11:35 am

    OPCache is almost 10% faster than APC on our production servers.

    Took half of the Cialis 20 mg pill about 10 pm yesterday. Somewhere in half an hour, I felt that the blood pressure increased. But two hours after I already had sex. In the following times, problems with pressure were no longer there, so now everything is in order.

  5. […] et c’est bon ! Pour des configurations un peu plus poussées d’APC je conseille cet article mais faites des tests car c’est vraiment pour des cas […]

  6. […] APC is the de-facto in PHP acceleration. It’s a PHP opcode cacher and works by caching PHP objects, functions, and database queries into your server’s RAM. If you run a WordPress web site – then it takes full advantage of APC out-of-the-box. See my post on The Perfect APC Configuration […]

  7. Ryan on January 3, 2014 at 10:29 pm

    Great information! This helped a lot with my site.

  8. […] A more detailed configuration can be found here: https://gregrickaby.com/the-perfect-apc-configuration […]

  9. […] More information about APC configuration may be found in The Perfect APC Configuration by Greg Rickaby. […]

  10. […] More information about APC configuration may be found in The Perfect APC Configuration by Greg Rickaby. […]

  11. […] More information about APC configuration may be found in “The Perfect APC Configuration” by Greg Rickaby. […]

  12. […] APC is the de-facto in PHP acceleration. It’s a PHP opcode cacher and works by caching PHP objects, functions, and database queries into your server’s RAM. If you run a WordPress web site – then it takes full advantage of APC out-of-the-box. See my post on The Perfect APC Configuration […]

  13. criznach on November 4, 2014 at 6:40 pm

    Just be sure that /var/www/temp exists and is writable, or change it to something that makes sense.

  14. Hosting WordPress with Hiawatha | DotBalm.org on March 15, 2015 at 5:45 am

    […] more on tuning APC for WordPress, I refer you to The Perfect APC Configuration by Greg Rickaby and, for more general info, to the APC configuration […]

  15. […] My first impression was that it was slow to load my WordPress homepage. Installing APC as per The Perfect APC Configuration – Greg Rickaby improved load times but I was still seeking fast page load […]

  16. FlyOn on January 30, 2016 at 1:02 pm

    even though PHP5 is out, this is still good information for apcu!

Leave a Comment