I spent this morning running the PageSpeed Insights tool in Google Chrome over this website and it came back with some good tips on how to speed up WordPress Apache to make this site run faster. I thought I would share how I approached making the recommended changes below.
The first critical issue that it threw up was to turn KeepAlive On, this means that Apache keeps the session alive to transfer multiples files. This reduces the latency as each new request for the multiple files that makes up a web page don’t have the overhead of opening and closing a connection. I found this great overview of the options here which is worth reading if you want more details.
I then made the following changes to my /etc/httpd/conf/httpd.conf
# # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 50 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 3
The second critical issue was a lack of compression so I needed to turn compression on and then ensure that all of the file types that benefit from compression were enabled with mod_deflate.
# # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # Despite the name similarity, the following Add* directives have nothing # to do with the FancyIndexing customization directives above. # AddEncoding x-compress .Z AddEncoding x-gzip .gz .tgz <FilesMatch "\.(php|css|html?|xml|txt|js|pl)$"> SetOutputFilter DEFLATE </FilesMatch>
The next issue that it identified was a lack of browser caching so I updated my .htaccess file to ensure that files that could be cached by the browser would be as recommended in this post.
Finally having spent some time on the Google PageSpeed website I saw they had developed the mod_pagespeed Apache module which combines a whole load of Apache web server performance best practices into a single install.
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm sudo rpm -U mod-pagespeed-*.rpm
Finally I reran PageSpeed Insights and got an overall PageSpeed Score of 94 (out of 100) which was great for a couple of hours works to really speed up WordPress Apache.
Music to Write this Code to
Blackalicious – Alphabet Aerobics is one of those songs that just gets faster and hypes you up hopefully just like you have done to your webserver.