Last week I was working with one of our customers on ways they could optimize their time to first byte (TTFB).
If you’re familiar with many of the webpage speed tests out there, you know this is one of the important benchmarks, as an indication of the responsiveness of a webserver or other network resource.
A lot of optimization that goes into TTFB is the back-end processing of the requested resource.
For example, a static webpage that isn’t being pulled from a database is going to have a faster TTFB than one such as WordPress where the content is being pulled out of mySQL.
WordPress Theme Optimizations
If your website is using WordPress then we have to first look at how well your web server is optimized for pulling this content out of the database.
I like to always encourage our customers to carefully select their WordPress theme and plugins as these can be two big factors into decreasing your TTFB.
Unfortunately a lot of themes and plugins are coded out of convenience without keeping server performance in-mind. WordPress developers nowadays are wanting to sell to the masses vs. creating a theme that’s optimize for high server performance.
I would estimate that the average WordPress theme customer, on say ThemeForest, doesn’t average more than a couple hundred visitors per month.
A lot of WordPress functions can also be completed without the use of a plugin. Even though they can be extremely convenient, it’s best to use a few as plugins as possible for optimal performance.
WordPress Server Optimization
Once you’ve optimized your WordPress theme and plugins you need to take a look at the back-end configuration on your server.
The first thing I like to check is the PHP handler. Since WordPress is obviously a PHP/mySQL application on the back-end, these are the first two points of optimization.
Optimizing PHP For WordPress
All of our Shared, Reseller, and VPS hosting packages allow for multiple versions of PHP. I highly recommend using PHP 7.0+ on your WordPress website. The performance and security advantages are tremendous and you’ll notice a substantial speed increase over PHP 5.6.
Once that has been selected, you need to take a look at the PHP handler. All of our Shared and Reseller hosting package utilize the lsphp handler, a byproduct of the LiteSpeed web server, which means it has already been optimized for you.
If you’re using our VPS hosting, you need to decide the best handler for your website. If you don’t want to spend the extra money on a LiteSpeed license, I recommend enabling PHP-FPM (FastCGI Process Manager).
PHP-FPM is now installed by default on all new Virtual Private Servers, you just need to actually login to Web Host Manger and enable it on your websites (I’ll demonstrate in the video below).
Optimizing mySQL For WordPress
Our Shared, Reseller, and VPS hosting packages all default with MariaDB.
MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. Some of the original mySQL developers started MariaDB after expressing concern once Oracle acquired mySQL.
Therefore it works the exact same as mySQL (your scripts will still function the same) but with much better performance and redundancy.
If you’re using one of our older virtual private servers, you may want to go to MariaDB upgrade in Web Host Manager and upgrade. However if you’re on one of our newer packages, it’s already installed by default.
Optimize Your my.cnf For WordPress
While installing MariaDB will help with performance, you still need to optimize your my.cnf file, as not all servers are alike.
Unfortunately for those on our Shared and Reseller hosting, you’re not able to optimize this file as we’ve already done it server-wide.
While we have optimized it for performance, we always have to remember these are Shared servers meaning we have to pick and optimization that works for the masses vs. individual websites.
Simply put, you’re going to have better WordPress performance on a VPS that you can customize.
With all of that said, the main point of optimization inside the my.cnf file is the innodb_buffer_pool_size.
[From mySQL documentation] InnoDB maintains a storage area called the buffer pool for caching data and indexes in memory. Knowing how the InnoDB buffer pool works, and taking advantage of it to keep frequently accessed data in memory, is an important aspect of MySQL tuning. For information about how the InnoDB buffer pool works, see InnoDB Buffer Pool LRU Algorithm.
The more RAM you have in your server you can allocate to the innodb_buffer_pool, the better the performance. As a general rule of thumb, many database administrators have recommended 80% of RAM in the server.
Percona has a fantastic article on their blog explaining this in detail as well as providing this handy chart:
|Total Server RAM||Buffer pool with 80% rule||Remaining RAM|
Personally, I’m always a bit more on the conservative side of things, and don’t go quite to 50%, but this is all personal preference. Especially if you’re running Web Host Manager/cPanel on your server you must also take that into consideration and allow enough RAM for it to operate smoothly.
Step By Step WordPress Server Optimization
To help put this all together, I thought it would be helpful to do a video tutorial where I installed a default copy of WordPress on a standard server and then compared the speed using the above optimizations:
As you can see, these very simple optimizations took my TTFB down to well under 400ms which is incredibly fast. I tested using the default WordPress theme without any plugins as I knew it doesn’t make unnecessary PHP/database calls.
There are still additional optimizations that can be made by adding caching, a content delivery network (CDN), etc. but I’ll cover those in another post.
I’m also going to be including all of this in my upcoming VPS Hosting 101 course in our new training center.
Ryan Gray is the founder and CEO of NameHero, one of the fastest growing independent web hosts in the United States. Ryan has been working online since 1998 and has over two-decades experience in Internet Entrepreneurship.
Leave a Reply