Guide To Optimizing WordPress Servers

After moving hosts for some reason my WP-Cache2 plugin stopped caching pages and I couldn’t work out why, so I’ve spent the last couple of hours looking for alternatives as I wanted to make sure I don’t get into trouble again with my new host, even though I have a VPS now rather than a shared host. I’ve managed to implement some good actions this morning which have significantly improved the page loading times of my WordPress blog. I’m sharing what I’ve done below which will definitely help other WordPress users and other users who have to manage a server, get faster loading times as well as reducing server strain. Much needed, particularly if you make it onto Digg’s homepage!

Install APC Part I

The first action I implemented was installing Alternative PHP Cache or APC. APC speeds up loading times by caching compiled WordPress PHP files so that the loading time the next time a page is loaded is much faster. This is different to WP-Cache2, which stores the HTML of a page for a user-defined period, which can cause problems if new comments or posts are made within this period i.e. if the page changes. APC doesn’t suffer from this problem and all page loads are dynamic.

APC and WP-Cache2 currently can’t be installed at the same time, although Mark Jaquith is working on trying to get the best of both worlds by finding a way to get APC and WP-Cache2 to work together, and I’m pretty sure he will crack it soon. However, given that I can’t even get WP-Cache2 to work by itself I didn’t even attempt to try some of Mark’s experiments. Initially I struggled to install APC as until two weeks ago when I moved from Blogware to WordPress I’d never even used MySQL before, much less configured a server. Luckily I found these instructions by Matthew Carroll on how to install APC which I almost managed to complete by myself, but Matthew was kind enough to finish the job for me.

Install APC Part II

Although my pages were loading faster after installing APC, Matthew and I were a bit disappointed by the speed as we were expecting more of a speed boost. I did a bit more digging around on the net and I found an old post by Mark Jaquith on WP-Hackers. Mark had been as enterprising as ever and had posted a custom script that uses APC as the object cache backend instead of WP’s default of caching objects to the disk. Once I installed this script my WordPress installation started to take full advantage of the APC installation and my pages literally started to fly, despite my 40-50 plugins. To install the script just rename it to object-cache.php and install it in wp-content/object-cache.php

Turn On MySQL Query Cache

MySQL 4 includes a query cache which helps if the database is running the same query over and over again on the same data set i.e. a page hasn’t changed; it is just being viewed over and over again. If the query cache is turned on MySQL can cache the result set, avoiding the overhead of repeatedly running the query. If you are on a shared server and you are public enemy number 1 for hogging database resources then this little beauty could be for you. Most decent hosts will probably have the MySQL qcache turned on by default, but it’s worth checking it just to be sure.

Post-Query Accelerator

Despite getting a significant speed increase from installing APC and also turning on MySQL’s query cache, I still wasn’t satisfied and I wanted more speed. The next optimisation step I found again came from Mark Jacquith in the form of the Post-Query Accelerator, which ensures that WordPress gets the most out of MySQL’s Query Cache. Here’s how it works in Mark’s own words:

WordPress’ post queries always ask for posts with post_date_gmt <= ‘$now’ where $now is set to the current time, to prevent posts in the future from showing up. This means that $now changes with each page load. For high volume MySQL sites, the system administrator might turn on MySQL’s qcache, in order to cache some SQL queries. The problem with $now is that it changes each time, so the query is never exactly the same again, and the cache doesn’t help. This plugin is designed to freeze $now to reflect the time of the most recent post or page. This does the job of preventing future posts from showing up, but doesn’t needlessly change $now on every load. This can lead to rather large query speedups on high volume sites or sites with many posts. If things like qcache and my.cnf are Greek to you, please don’t use this plugin. Those who need this plugin will know that they need it, and without a properly configured my.cnf with query caching, it will do nothing.

Installing the plugin couldn’t be easier. Just download and save the file named post-query-accelerator.php. Upload it to your /wp-content/plugins/ directory and activate it

, , , , , , , , , ,

58 Responses to Guide To Optimizing WordPress Servers

  1. _ck_ August 7, 2006 at 4:58 pm #

    Nice roundup.
    You should mention that Mark Jacquith’s Post-Query Accelerator won’t be needed in 2.1 though the mainstream folks are many months away from that, certainly not this year with over 250 tickets in the trac system.

    Only other thing I know of, to add to your list, is to turn on the little mysql summary that WordPress has via Jerome’s Query Diagnostics http://vapourtrails.ca/downloads/jeromes-query-diagnostics.zip
    which writes a summary of all the select calls at the end of your page footers (commented out, just do a view source) and see if any are taking an usual amount of time.

  2. Mahmood Al-Yousif January 31, 2007 at 4:00 pm #

    Thank YOU Everton for the resources you provided. I shall keep WP2 on for a few days to evaluate the site’s speed then switch it off to compare and make a decision then.

    If you’re still around, can you please let me know what you actually put in the [apc] section of the php.ini file? I’ve just put the wp-cache-config as instructed, but should there be any other things in there or should APC be left at default values?

  3. Avatar of Everton
    Everton January 31, 2007 at 4:05 pm #

    You’re lucky Mahmood as I’m home today as I’m not well.

    To get APC and WP-cache to work together you only need to change one line – read more here

  4. Mahmood Al-Yousif January 31, 2007 at 6:11 pm #

    Ah, thank you I read and implemented that already. I was wondering if there are any other settings that should be in the [apc] section of the php.ini file?

    Get well soon though! And thanks once again for this excellent article which helped a lot.

  5. Avatar of Everton
    Everton February 1, 2007 at 9:35 am #

    Not that I can remember Mahmood

  6. Dan and Jennifer June 18, 2007 at 2:23 pm #

    Hey Everton,

    Awesome post!

    Would you mind sharing with us your my.cnf file? I’m making some performance enhancements to our new virtual (VPS) server (with HostDime.com – I’m really liking the setup).

    We’ve got mod_php and PHP eAccelerator (PHP object caching) running already so caching PHP files, so MySQL performance is the next step.

    I’m now running with the default Mysql config file, and was going to turn on query cache, but would like to see what you’re doing overall. BTW, we’re running with a TOTAL 512MB in our VPS (virtual server)…

    Oh, regarding Post Query Accelerator – did you have any problems with it impacting your WordPress admin functions (i.e. draft posts not showing up?). I figure not, but just checking.

    Thanks!

    Have an awesome day!
    Dan

  7. Dan and Jennifer June 18, 2007 at 3:23 pm #

    Hey Everton,

    Awesome post!

    Would you mind sharing with us your my.cnf file? I’m making some performance enhancements to our new virtual (VPS) server (with HostDime.com – I’m really liking the setup).

    We’ve got mod_php and PHP eAccelerator (PHP object caching) running already so caching PHP files, so MySQL performance is the next step.

    I’m now running with the default Mysql config file, and was going to turn on query cache, but would like to see what you’re doing overall. BTW, we’re running with a TOTAL 512MB in our VPS (virtual server)…

    Oh, regarding Post Query Accelerator – did you have any problems with it impacting your WordPress admin functions (i.e. draft posts not showing up?). I figure not, but just checking.

    Thanks!

    Have an awesome day!
    Dan

  8. Everton June 19, 2007 at 6:43 pm #

    Here’s my.cnf file. PLease don’t ask me any questions about the settings – beyond my ability to answer!

    [mysqld]
    safe-show-database
    old-passwords = 1
    skip-locking
    character-sets-dir=/usr/share/mysql/charsets/
    query_cache_limit=3M
    query_cache_size=48M
    query_cache_type=1
    max_user_connections=300
    set-variable = max_connections=500
    interactive_timeout=30
    wait_timeout=20
    connect_timeout=5
    thread_cache_size=1024
    thread_concurrency=2
    key_buffer=24M
    join_buffer=3M
    max_allowed_packet=32M
    table_cache=3096
    record_buffer=3M
    sort_buffer_size=3096K
    read_buffer_size=3096K
    max_connect_errors=10
    read_rnd_buffer_size=3096K
    myisam_sort_buffer_size=48M
    socket=/var/lib/mysql/mysql.sock

    [mysql.server]
    user=mysql
    basedir=/var/lib

    [safe_mysqld]
    open_files_limit=7092

    [mysqldump]
    quick
    max_allowed_packet=64M
    max_allowed_packet=64M

    [mysql]
    no-auto-rehash

    [isamchk]
    key_buffer=48M
    sort_buffer=48M
    read_buffer=24
    write_buffer=24M

    [myisamchk]
    key_buffer=48M
    sort_buffer=48M
    read_buffer=24M
    write_buffer=24M

    [mysqlhotcopy]
    interactive-timeout

  9. Avatar of Everton
    Everton June 19, 2007 at 7:43 pm #

    Here’s my.cnf file. PLease don’t ask me any questions about the settings – beyond my ability to answer!

    [mysqld]
    safe-show-database
    old-passwords = 1
    skip-locking
    character-sets-dir=/usr/share/mysql/charsets/
    query_cache_limit=3M
    query_cache_size=48M
    query_cache_type=1
    max_user_connections=300
    set-variable = max_connections=500
    interactive_timeout=30
    wait_timeout=20
    connect_timeout=5
    thread_cache_size=1024
    thread_concurrency=2
    key_buffer=24M
    join_buffer=3M
    max_allowed_packet=32M
    table_cache=3096
    record_buffer=3M
    sort_buffer_size=3096K
    read_buffer_size=3096K
    max_connect_errors=10
    read_rnd_buffer_size=3096K
    myisam_sort_buffer_size=48M
    socket=/var/lib/mysql/mysql.sock

    [mysql.server]
    user=mysql
    basedir=/var/lib

    [safe_mysqld]
    open_files_limit=7092

    [mysqldump]
    quick
    max_allowed_packet=64M
    max_allowed_packet=64M

    [mysql]
    no-auto-rehash

    [isamchk]
    key_buffer=48M
    sort_buffer=48M
    read_buffer=24
    write_buffer=24M

    [myisamchk]
    key_buffer=48M
    sort_buffer=48M
    read_buffer=24M
    write_buffer=24M

    [mysqlhotcopy]
    interactive-timeout

  10. John Black August 1, 2007 at 12:04 am #

    Wp-Cache plugin the only thing you need : ) decreases the load from 50 to 0.4 : )

  11. John Black August 1, 2007 at 1:04 am #

    Wp-Cache plugin the only thing you need : ) decreases the load from 50 to 0.4 : )

  12. wordpress quickstart guy August 14, 2007 at 3:15 am #

    very detailed explaination on the server installation!

    great post.

  13. wordpress quickstart guy August 14, 2007 at 4:15 am #

    very detailed explaination on the server installation!

    great post.

  14. Ginn Wei October 21, 2007 at 9:41 am #

    Thanks for the information. It will definitely come in handy if I’m getting a VPS for my blog. Nowadays, everything needs to be fast. :)

  15. Ginn Wei October 21, 2007 at 8:41 am #

    Thanks for the information. It will definitely come in handy if I’m getting a VPS for my blog. Nowadays, everything needs to be fast. :)

  16. Stereophonics November 27, 2007 at 7:05 pm #

    over 250 tickets in the trac system doesn’t seem right

  17. Webdesigner February 5, 2008 at 6:17 am #

    Useful roundup! I added it to my bookmarks. Thanks!

  18. Webdesigner February 5, 2008 at 6:17 am #

    Useful roundup! I added it to my bookmarks. Thanks!

  19. ana July 16, 2008 at 7:21 pm #

    Great tips.

  20. ana July 16, 2008 at 8:21 pm #

    Great tips.

  21. Internet marketing October 17, 2008 at 11:41 am #

    thx 4 useful article

  22. Internet marketing October 17, 2008 at 12:41 pm #

    thx 4 useful article

  23. watch tv October 19, 2008 at 4:37 am #

    These are good guides and thank you very much! I am always looking for ways to reduce the taxation on my servers.

  24. watch tv October 19, 2008 at 5:37 am #

    These are good guides and thank you very much! I am always looking for ways to reduce the taxation on my servers.

  25. Mechanical Engineering December 3, 2008 at 8:01 am #

    Good, I have added to my favorites,
    this title:Guide To Optimizing WordPress Servers | Connected Internet

    By the way, i want make a friendlink with your site~ if you could,please do and mailto me[sharks1039@gmail.com],wish to you~161

  26. Mechanical Engineering December 3, 2008 at 9:01 am #

    Good, I have added to my favorites,
    this title:Guide To Optimizing WordPress Servers | Connected Internet

    By the way, i want make a friendlink with your site~ if you could,please do and mailto me[sharks1039@gmail.com],wish to you~161

  27. perde February 13, 2009 at 2:08 am #

    thx 4 useful article thnks

  28. perde February 13, 2009 at 3:08 am #

    thx 4 useful article thnks

  29. Make money online March 13, 2009 at 12:37 pm #

    Making money online is not always as easy as people think but it is possible and when you find something that works for you, it is great and you run with that.

  30. Make money online March 13, 2009 at 1:37 pm #

    Making money online is not always as easy as people think but it is possible and when you find something that works for you, it is great and you run with that.

  31. Robert Fitzpatrick May 27, 2009 at 9:53 am #

    I really need to get on board with WordPress, it seems to be dominating the internet.
    Robert

  32. Robert Fitzpatrick May 27, 2009 at 10:53 am #

    I really need to get on board with WordPress, it seems to be dominating the internet.
    Robert

  33. Frumusete July 1, 2009 at 12:16 pm #

    Big thanks for tips

  34. Frumusete July 1, 2009 at 1:16 pm #

    Big thanks for tips

  35. Accountants/CPA Directory August 15, 2010 at 7:45 am #

    I was trying to find help getting a business and found transactionprofessionals and went with them. I am very happy I researched and spent some time to find expert help.

  36. Hurda August 20, 2010 at 12:06 pm #

    I think type of site that is useful in sharing information and it is important to shar.Web proliferation of new developments in the field of design and entrepreneurial spirit of people who have very beautiful and pleasing to be professional

  37. Haliyikama August 21, 2010 at 7:13 am #

    First of this type of site we provide users the opportunity because of this beautiful and quality we give our respect.

  38. Web Tasarim August 21, 2010 at 5:24 pm #

    I think type of site that is useful in sharing information and it is important to shar.Web proliferation of new developments in the field of design.Thank you.

  39. Buz August 23, 2010 at 10:12 am #

    possibility of sharing and social solidarity at a level just fine

  40. Logar August 24, 2010 at 7:29 am #

    How to speed up internet technology? Thank you.

  41. Perde August 25, 2010 at 7:59 am #

    Your site is very useful in terms of cultural exchange.Thank you.

  42. konteyner August 26, 2010 at 6:59 am #

    your site is important in terms of sharing between people think thanks.

  43. Enristlensisa August 27, 2010 at 5:02 am #

    just wanted to say that this best Registry Cleaner site is realy good and Im happy that i found it
    I’ve gotten exposed to quite a lot of info here and just wanted to give my 3 cents. Im about to write a good article for this forum about
    best Registry Cleaner , [url=http://www.registry1000.com/2010/05/09/best-registry-cleaner/]best Registry Cleaner [/url] and I’ll publish it as soon as i finish it.
    best Registry Cleaner fvmykrckdxmqekrcdd
    cheers!

  44. palet August 27, 2010 at 6:34 am #

    Very useful in terms of sharing people. Thank you.

  45. Enristlensisa August 27, 2010 at 7:17 pm #

    just wanted to say that this Asics gel women’s website is realy great and Im happy that i found it
    I’ve gotten exposed to quite a lot of stuff here and just wanted to give my 8 cents. Im about to write a great article for this forum about
    Asics gel women’s , [url=http://www.shopshopsss.com/?p=22]Asics gel women’s [/url] and I’ll publish it as soon as i complete it.
    Asics gel women’s fvmykrckdxmqekrcdd
    cheers

  46. Cöp Konteyner August 28, 2010 at 2:19 pm #

    I always follow your site thank you wish you continued success. Thank you.

  47. cheap iphone August 28, 2010 at 7:26 pm #

    I Really Enjoyed The Blog. I Have Just Bookmarked. I Am Reguler Visitor Of Your Website I Will Share It With My Friends Thanks

  48. Corona Del Mar Dentist August 30, 2010 at 4:08 am #

    Your smile is as beneficial as any piece of clothing you place on. People today observe your smile 1st and foremost. A incredible smile might be all will want to construct that impression you’ve worked so tricky to make. Corona Del Mar Dentist

  49. webtasarim August 31, 2010 at 12:17 pm #

    web design a site that has done a good share.thanks

  50. webtasarim September 1, 2010 at 6:47 am #

    I wish you continued success sharing.thanks

  51. wine favors September 2, 2010 at 1:52 pm #

    The study sited is indisputable. I have to say that tom will want to examine his details and re-think his conclusion. The authorites have spoken along with the rest of really need to to respect that. Thanks for the perfectly laid out into.

  52. Hali yikama October 4, 2010 at 9:09 am #

    nice work at a level of social solidarity and the opportunity to share
    a very good time thank you..

  53. Haliyikama October 27, 2010 at 10:33 am #

    This has been a great admin. fun and very nice. beautiful study. Thank you again

  54. matin e October 29, 2010 at 3:32 pm #

    nice post
    thanks for your great information

  55. matin e October 29, 2010 at 3:36 pm #

    thanks i like your great websit
    http://makhzannoor.org

  56. Anonymous March 12, 2011 at 12:54 pm #

    very detailed explaination on the server installation!

    great post http://www.escortum.org

  57. billur halı yıkama April 28, 2011 at 7:05 am #

    Shares is very beautiful. Thank you all.

  58. Ibrahim July 19, 2011 at 8:56 am #

    sharing is very beatiful and high quality thanks