Give us a call: (800) 252-6164
How to make your website load in under 2 seconds using Apache, Nginx, Redis, PHP7, MySQL, and WordPress

How I Got My Pages to Load in Under 2s*

April 2, 2018 | By David Selden-Treiman | Filed in: hosting.

*Your speed times will probably vary, depending on your location, internet connection speed, etc.

My Results

I started out with the goal of getting my websites to load as quickly as possible (even without using a CDN). After a lot of research, trial-and-error, and development, I created the following combination for an efficient web server. The net result is load times under 2 seconds for my entire WordPress-based homepage:

Potent Pages' Loading in Under 2s: Pingdom

Potent Pages’ Homepage Loaded in 775ms according to Pingdom.

Potent Pages' Loading in Under 2s: GTmetrix

Potent Pages’ Homepage Loaded in 1.2s according to GTmetrix.

Why You Need Quick Load Times

Getting a website to load quickly is one of the most important aspects of website design. Your website doesn’t count for much if your visitors aren’t able to look at your page or have already left because it loads too slowly. So, it’s important to get your website as quick and efficient as possible to your visitors.

According to research by kissmetrics, 47% of visitors expect a web page to load in 2 seconds or less. Even worse 40% abandon a website that takes longer than 3 seconds to load. Emphasizing load times importance, 79% of shoppers who are dissatisfied with a website’s performance are less likely to buy from the same site again. Finally 52% of online shoppers state that fast page loading time is important to their loyalty to the site.

So quick load time is essential to satisfied customers and achieving high conversion rates. But how best can we go about this? Most people end up using Apache as their primary web server and simply serve their site directly from a shared hosting platform. According to w3techs.com, “Apache is used by 47.2 %” of known web servers. While this is usually economically less expensive, this can end up costing a lost opportunity.

Apache Is Great For…

Apache is great at handling server-side scripting, such as PHP, and for serving multiple sites at the same time. It’s relatively straightforward to configure and includes useful tools like htaccess files. Unfortunately though it can be a bit slow. Apache is designed for fewer connections and is slower to process those connections because the scripting languages are loaded every time. This slows things down. So while Apache is great for serving dynamically generated content directly (because the language interpreter is loaded befo?rehand) it can be slower when serving static content. But there is a faster way for static files.

Nginx Is Better For…

Enter nginx. Nginx is like the mirror image of Apache. While Apache is great for dynamic content, Nginx is ideal for static content. In fact everything about nginx is designed for serving static content as quickly and as efficiently as possible. Nginx doesn’t even contain in-built support for scripting languages such as PHP or python. This makes it faster and more memory-efficient for serving static files. Instead you’ll have to manually configure these to allow for dynamically generated content. So you can configure nginx to work as a standalone server and many people do…

…but what if there was a way to combine Apache and nginx together?

Combining Them Together

Instead of simply serving either dynamic content quickly and having to manually configure all of the PHP administration, what if we could simply have nginx serve static content and then for all Dynamic content simply pass it to Apache?

This method would allow you to use htaccess files as needed for dynamic content, and would allow you to have the benefits of speed on both the static and dynamic sides.

This would also allow you to use standard WordPress configurations if you’re using WordPress, and allow you to more easily transfer your sites from an existing Apache server to an Nginx-Apache combination setup.

This is the setup I discovered and that allows me to load my client’s sites, as well as my own, very quickly. Here’s how I did it…

 

Automatic Installation?

If you like the result of the tutorial, but run into problems or would just like to have the work done automatically, we can help you with that. We have an automated script that can SSH into your server and run this tutorial from beginning to end (as long as it’s running CentOS 7). If you would like this done for you ($100), please contact us using the form below.

 

    Get Started







     


    Part 1: Introduction and Planning

    Why it’s important to have your pages load in under 2 seconds, and a plan of how we will set up and configure the server.

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Initial setup of the server, including installing CentOS7, installing tools, installing SSH and SSL, enabling repositories, and installing support packages.

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 3: MySQL, Apache, PHP7, & Composer

    Installation of MySQL database serverApache web serverPHP, and Composer package manager for PHP

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 4: PHPMyAdmin & Redis

    How to download, install, and configure PHPMyAdmin; How to install and configure Redis

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 5: SSL Certificate & Apache Configuration

    How to create a self-signed SSL certificate; how to configure Apache as a PHP backend

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 6: FTP & DNS

    How to install and configure an FTP server with dynamic users; how to set up a DNS server

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 7: Installing Nginx

    How to download, build, and install Nginx with additional modules

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 8: Configuring Nginx

    How to set up Nginx configuration files including (with explanations): nginx.confGzip compression settingsvisitor browser caching settingsSSL settingsreverse proxy settings for sending data to the Apache serverreverse proxy connection configurationsfile access restrictions, and WordPress configuration settings

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 9: Adding a WordPress Website

    How to add a WordPress website to the server including configuring the DNS Server, adding a verified SSL certificate, either manually or for free using Let’s Encrypt, setting up FTP for your site, configuring Apache, configuring Nginx, uploading your WordPress site files, and importing your MySQL database.

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.

    Part 10: WordPress Website Speed Improvements

    Speeding up your WordPress installation using a Redis plugin and a caching plugin.

    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.


    David Selden-Treiman, Director of Operations at Potent Pages.

    David Selden-Treiman is Director of Operations and a project manager at Potent Pages. He specializes in custom web crawler development, website optimization, server management, web application development, and custom programming. Working at Potent Pages since 2012 and programming since 2003, David has extensive expertise solving problems using programming for dozens of clients. He also has extensive experience managing and optimizing servers, managing dozens of servers for both Potent Pages and other clients.


    Tags:

    Comments are closed here.

    What Is The Best Web Hosting Provider?

    Finding the best web hosting provider for your needs is an important step in optimizing your website. There's a lot to consider. Here are our basic recommendations:

    Simple Websites

    For simple websites, you have a lot of options. Most web hosts will do acceptably for a simple small-business website or blog.

    That said, we recommend avoiding website builders so that you maintain control of your website.

    VPS Hosting

    If you just need a simple VPS, most providers will work well. Different providers have different downtimes, but the big differentiators are cost.

    Providers like AWS and Google Cloud tend to be much more expensive than more specialized providers.

    We recommend Digital Ocean and Hetzner if you're looking for a good VPS provider at a good price (it's what we use.)

    High Performance Hosting

    If you're looking for high performance web hosting, you're going to need something more specialized.

    You can't just expect a simple cPanel host to give you what you'll need. You need a custom configuration.

    Generally, you'll need either a managed host, or you'll need to get your servers configured with custom configurations.

    If you're looking for a high performance hosting provider, we offer hosting designed for high-availability and high-traffic.

    WordPress Hosting

    What WordPress Hosting Should You Get?

    There are many considerations when getting a WordPress hosting provider. Focus on the performance needs of your website.

    WordPress Hosting Setup

    When setting up your WordPress hosting, or switching hosts, there are a number of steps to complete. These include:

    WordPress & Security

    There are a number of WordPress security threats to contend with. We recommend using a plugin like WordFence to help secure your site.

    WordPress Backups

    Make sure to also back-up your site. It's absolutely essential, and ideally use an off-site backup provider that's different from your hosting provider.

    WordPress Speed Improvements

    There are a number of ways to improve the speed of your WordPress site on its hosting.

    There are a number of plugins that can help improve your site's speed.

    DNS

    DNS Records

    There are many different types of records, each with their own purpose. These include: SOA, A, TXT, CNAME, PTR (reverse DNS), and more. On some servers, you can also set up wildcard records.

    The records you need will depend on what you're doing; WordPress sites require different records than mail servers, for example.

    Propagation

    The process of your records transmitting to DNS servers around the world is called propagation. It normally takes 48 hours, but you can speed it up a bit with some planning.

    Testing

    To test your DNS records, there are 2 main tools: dig and nslookup. Each is very helpful in its own specialty.

    Reliability & Security

    There are a number of ways to improve your DNS reliability and security.

    • Split Horizon allows you to separate networks, either for intranets or for separating by geographic region.
    • GeoDNS allows you to give different records to different locations based on the requesting IP address. This allows you to create your own CDN, speeding up your site.
    • DNS over QUIC speeds up your DNS requests and gives you better DNS security by encrypting your DNS connection.
    • DNSSEC allows you to sign and encrypt your DNS connection, ensuring that nobody is changing your records.
    • DNS over HTTPS allows your visitors to request your DNS records over an encrypted connection.

    Internationalized Domains

    Internationalized domain names allow character encodings other than Latin characters. They have their own methods for backward compatibility.

    Scroll To Top