Since a lot of people out there land on my personal website looking for help and assistance making really really fast websites, which rank well in Google, often I’m asked questions about how to make fast sites.
If you’d like to make the fastest website in the World, how would you go about doing this?
Well, the short answer is, every single element needs to be 100% optimal.
I’ve been accused by some developers of practicing “micro-optimizations” which I take to be a compliment. Of course I practice this. Like a Forumla 1 engineer, optimal is a case of piling micro-optimization after micro-optimization on top of each other in order to achieve a stack of optimized machinery which, when all is added together, is as fast as it is possible to go.
So where to start?
Let’s begin at the beginning. I’m going to talk about hosting a PHP web application, like WordPress. You can use JS frameworks, or write plain HTML which is very fast. But the majority of businesses use a CMS, and the majority of people who use a CMS use WordPress, because it is stable and easy for less technical members to familiarise with. So let’s speed up the typical WordPress stack.
Your Domain Nameservers and DNS
The nameservers you use to host your domain records, and the DNS records themselves matter in terms of speed.
There are two issues here: lag and server response time. There are other considerations here, too, such as TTL, which will tell all the various network caches around the world how long your domain DNS records are authoritative. Unless you are making regular changes to your DNS, and unless you have a particularly fast and globally available namesevers, you should set this to be pretty long, like 12 or 24 hours (or more).
My recommendation for your nameservers is to look at globally available service like AWS Route 53. These cost something like $0.50 a month to host all your domain’s DNS, but are blazing fast globally.
Set your domain @ records TTL to be 48 hours or longer if you don’t expect to change these – allow network level caching to do it’s thing.
Your Hosting Machine & Stack
There are a lot of elements to the hosting machine, but general rules apply, as well as some specifics.
For WordPress sites, I recommend either:
If your site is a PHP application running Magento or similar, I recommend to try your site on Cloudways – use Vultr.
Note if your site is WordPress with WooCommerce, have a look at the Best WooCommerce hosts here.
If you are looking for optimal, do not use shared hosting. This is a recipe for disaster, because (and the clue is in the name) your site will share resources with others, leading to bottlenecks.
Use a VPS, Cloud Host or Dedicated Server
You want your resources dedicated to your instance. Which is best depends a little on the size, scaling requirement, and location of your hosting machine – all of which are debatable – and whether or not you need clustering or redundancy to be factored in.
Buy as much hardware as you can afford… but not more than you need
I often see people throwing hardware at sites in an effort to go faster. It doesn’t work like this. You need RAM and CPU to be sufficient, and there is a performance advantage to certain choices (like choosing SSD drives, or having more CPU cores for certain operations) but in a lot of cases, the hardware needs only to be sufficient. Big enough, and capable of holding the fastest software is sufficient here.
The Web Server – Nginx
Apache is slow. There, I’ve said it. It is also a very powerful and stable web server. In my opinion, Nginx should be taking the initial requests, however, and either serving directly, or caching apache’s slight slowness out of the mix.
Use PHP 7.3
The most recent version of PHP is faster than the last. It’s also more secure. But, you will likely need to refactor your code to be error free, particularly if you have code which is a few years old. Consider dropping support for older versions of PHP in your code, if you will never use them.
MySQL – Consider MariaDB 10 or MySQL 8
MySQL 8.0 is looking likely to be a real performance boost. Until this is regularly available, MariaDB 10 is a really fast alternative. Please note that conversion from MySQL 5.7+ to MariaDB is not straightforward, so you need to make a decision at this point (there are other ways to import data, but it is worth remembering to make your decision at MySQL 5.6 with this in mind).
There are other (somewhat political) reasons to make the MySQL vs MariaDB choice. I’ll not get into politics here, except if it impacts speed. MySQL 8.0 shows a moderate performance boost over all equivalents in my most recent benchmarking.
Look at your Code
Maybe I should have led with this. Slow performance is almost always a result of some code (or lots of code) in the system which does things the long way around. You need all the elements of your code to do things fast. Think fast first when you are choosing everything software related, including your theme and plugins if you use WordPress.
Got Questions – Leave the below
There’s obviously lots more I can add in here. If you’re interested to know more, see my long guide to optimizing WooCommerce for some granular stuff you could get into, or ask a question below.
I aim to build this section out more over time to become a working guide to the fastest possible stack for your PHP web applications.
Please ask and complain if you agree, disagree or want to know more.