WordPress Optimization Tips
January 19th, 2012
Any dynamic CMS application like WordPress can be a bear to maintain, and strain your server hardware. WordPress, and it’s many plugins available, can make your website slow down to a crawl. Fortunately we have years of experience with WordPress and high volume traffic. We have some great tips to help optimize your WordPress. A slow loading web site blog can not only mean an increase in bounced visitors to your site, but can also mean a decreased ranking with Google. So it’s critical you make sure your site loads fast.
Here are some recommendations to help optimize your WordPress for search engine optimization (SEO) but also for speed. Unfortunately, some of these options are only available when you go with a managed VPS, and not available in a shared hosting environment.
Replace Apache With LiteSpeed
We always recommend replacing Apache with another web server. Apache is great for compatibility, but the worst with web site performance. Dynamic applications like PHP based apps, don’t scale well with a high volume of traffic, and isn’t efficient with memory usage. We recommend using LiteSpeed because of it’s compatibility with Apache configuration files, it’s support of mod_rewrite entries, security and it’s performance with PHP.
LiteSpeed offers the performance of mod_php, but the security when using suPHP. Unlike a mod_php setup, the LiteSpeed web server runs PHP as your user/group. No more having to worry about the proper permissions for folder when uploading content through WordPress.
The added benefit when using LiteSpeed is compatibility with Apache configuration files. This means control panels like DirectAdmin are fully compatible with Apache, and we typically recommend this configuration. Yes LiteSpeed is a commercial application, but the cost is minimal and well worth the monthly fee.
Limit The Amount Of WordPress Plugins
Without knowing the plugins you use for your WordPress blog, it always makes sense to limit the amount of plugins you use. Unfortunately, not all plugins are created equal. Some plugins are complete resource hogs. Some plugins are coded poorly, and can affect the load time of every web page. Others insert unneeded HTML code on every web page, when only used on one page. If unsure, remove each plugin one by one and use a tool like Google Chrome Developer Tools to monitor the load time of your web pages.
Install a PHP Accelerator
PHP out of the box scales just ok. PHP is an interpreted language. Code written in PHP is converted into machine readable code (bytecode) and served through your web server. This process is time consuming, and adds overhead when every web page is loaded. It also makes your web site much more CPU bound, since PHP must compile the code every time.
Fortunately there is a solution to this issue. Install an opcode cache for PHP. There are many PHP accelerators available such as: eAcceleator, ionCube PHP Accelerator, XCache, and Zend Optimizer.
From our experience with compatibility, we recommend the PECL package APC. PHP accelerators are not perfect, and sometimes can cause issues with the created PHP code. From our experience APC seems to be the most reliable, but unfortunately isn’t the fastest. In tandem with a PHP accelerator, we also recommend installing a cache engine plugin within WordPress.
Use a Cache Engine
As mentioned previously, every web page with WordPress is generated dynamically with PHP scripts. This can slow down your web page generation time. We recommend not only using APC, but then adding a caching engine within WordPress. The two recommended WordPress plugins are:
Each plugin has it’s advantages and disadvantages and should choose the one based upon your situation. We typically recommend using WP Super Cache first.
WP Super Cache
WP Super Cache converts your entire blog into static HTML. Static HTML always loads faster than dynamically generated PHP code, and can handle a much higher amount of web site hits per second. This plugin is perfect if all of your content is static and you do not have any dynamically generated content that changes often on a web page (ie stock quotes).
W3 Total Cache
Some plugins do not work with WP Super Cache. If this is your situation, we then recommend using W3 Total Cache. Unlike WP Super Cache which converts all of your WordPress blog into static content, W3 Total Cache uses various methods to cache code within PHP. This allows for better flexibility with the choice of plugins you use, but from our tests runs slightly slower then WP Super Cache. W3 Total Cache can be complicated to setup, but has many more options, is much more flexible, and can work with memcached.
Use the Genesis Framework
We recommend not using the default themes, or the many freely available themes for WordPress. Many WordPress themes are junk, or have hidden URLs that help the developer’s SEO. It is possible to hire a web developer to create a custom theme for your WordPress blog, but this can be time-consuming and costly.
A much cheaper alternative we recommend is the Genesis WordPress Framework by StudioPress. It’s a great WordPress theme to base your site on.
Fortunately if you aren’t a web designer, Genesis offers many child themes you can get your web site up and running in no time. Genesis not only allows for you to create quickly a professionally looking web site, but is optimized for SEO and quick loading. We recommend StudioPress Genesis Framework to all our customers.
The SQL database MySQL is an integral part of WordPress. Since every page generated is stored within MySQL, it’s critical MySQL is optimized.
Depending upon the amount of memory available with your instance, and the size of your database it’s critical it’s all in memory and not using swap space. Using your instance disk swap tends to degrade performance very quickly. Therefore the configuration settings for your MySQL can be very dependent upon the amount of postings you have on your blog. Below is a general recommendation, but is not comprensive.
By default WordPress installs the database tables as MyISAM storage type. While this is ok for a small web site, this can cause problems with a site that has many reads and writes to it’s database tables. The MyISAM format performs table locking when updates to the table occur. This means if another process needs to write to the same database table, it must wait until the other process completes. This can cause delays in web page generation. MyISAM is really just a glorified flat file database format. Read for fast reads, but poor with most other database operations.
The table format InnoDB on the other hand supports row locking, which means multiple reads and writes can use the same table concurrently. This prevents delay in page generation. Not every table within WordPress must be converted though. Some tables can perform better with MyISAM since they are mainly read only.
From our experience, tables wp_options and wp_comments should be converted to InnoDB.
Use a CDN
If you have a web site visitor coming from California, but your server is located in New York, their request must travel across the country. Latency, or the time it takes to across the country, is at minimum 100ms. Add this delay for the many requests needed to generate a complete web page, it can add easly 2-3 seconds to the load time of your web site.
Using a Content Delivery Network, or CDN, is the best option to speed up your static content. CDNs have multiple locations around the world to store your content. By pushing your content to a CDN, the web site visitor will get access to your content from the nearest location to them. This means decreased time to load your static content. The added benefit is your web server, which is now just focused on generating dynamic web pages, no longer has the additional strain of serving static files.
We recommend using Amazon’s Cloudfront service, but there are many other CDN providers available.
Pick An Outstanding Hosting Provider
The last item, but definitely not least option affecting the performance of your WordPress blog, is your choice of hosting provider. If using shared hosting, many of the options mentioned above are limited by the expertise and flexibility of your hosting provider. Some may have options to help with the performance of your blog, but most need to optimize for all their customers in a cookie cutter fashion.
Unfortunately it is also the dirty little secret many overload their shared hosting servers to ensure a profit. Services that are unlimited does not exist in the real world. They must limit something, even though they are offering “unlimited” disk space and bandwidth. Usually with dynamically generated web sites like WordPress blogs, the limiting factor is the amount of CPU power available. This means your site loads slowly, and is the primary factor to your site’s lag. In some cases the hosting provider will suspend your account because the amount of CPU used by your web site. If your web site is another other than a personal blog, you need to migrate to a VPS.
Virtual Private Servers (VPS) act just like a real server – you have your own dedicated CPU, memory, and disk space. Though compared to a dedicated server, a VPS is at the fraction of the cost.
Unfortunately many VPSes are unmanaged. This means you are responsible for everything: backups, security, software updates, and monitoring. Many people don’t have the time, or expertise to manage their own server.
Everything is done for you, and is no different than a shared hosting account. It service is still a black box to you, and you just have to focus on your blog.
The amount of time saved by hiring an hosting firm who’s an expert in optimizing WordPress is well worth the cost. While we have our hosting services, we also do consulting for customers who need help with their existing WordPress setup.
Leave a Reply