How to Optimize Webserver for WordPress Performance

Nginx / Apache Web Server
NGINX vs Apache Web Server

If you are going to run a website, you should take into consideration several factor that affects the performance such as configuration of the web server, database and applications that the website will eventually run on.  After years of reconfigurations we have developed a sure way to optimize our webserver for WordPress to improve performance.

Deciding on Server Infrastructure

A blog can start off small but over time develop into a huge undertaking especially when there’s a rise in traffic.  For the past twelve years, we’ve utilize several available options in an attempt to optimize the server for performance and in most cases the attempts failed and caused delineation in traffic.  In the past we experienced:

  • Internal Server Errors
  • Database errors due to database server running out of memory and resources
  • Slow page load
  • Disk usage errors

These errors were a factor of the poor configurations of the tools that were used to operate the server and the web applications.  Prior to three years ago the website infrastructure was the following:

  • Server Operating System: CentOS 5.4
  • Web Server: Apache 2.0 / MPM Prefork / PHP
  • Database Server: MYSQL
  • Content Management: Joomla

Regardless of the configuration the server could not be optimized for better performance due to the heavy load on the server.  The website operated under automation which is a drain on memory and resources, therefore performance decreased and the website went to a crawl and in most cases crash.  We had to figure out the relative cause of the issues so we did, and diagnose the issue.

  1. The webserver, database and content management system ran on the host machine and uses up all of the resources.
  2. Content management system was prone to hacking and lack luster templates.
  3. Database could not handle increased webserver requests
  4. Webserver was poorly configured which causes the database server to use up memory and crash the host machine.

Server Setup: Single machine to Virtualization

The biggest problem we had was the fact that we ran every thing on a single machine. The host machine ran the webserver and database which means it was sharing resources.  That was a problem because if the database used up the memory of the host machine it crashes or if the host machine got hacked it affects everything.  To fix that issue we decided to revise our server setup.  Instead of one machine decide to build virtual machines.

In computing, a virtual machine (VM) is an emulation of a particular computer system. Virtual machines operate based on the computer architecture and functions of a real or hypothetical computer, and their implementations may involve specialized hardware, software, or a combination of both.  This means we now have the following:

  • Host Machine Operating System (OS): CentOS 6
  • Webserver VM OS: Debian 8
  • Database VM OS: Debian 8

Content Management:  From Joomla to WordPress

Ever since we started building websites, we knew we would use content management systems but there were too many options to choose from.  At first we tried WordPress, which was a free and open-source content management system based on PHP and MySQL. Features include a plugin architecture and a template system. It is most associated with blogging but supports other types of web content including more traditional mailing lists and forums, media galleries, and online stores.  It is used by more than 60 million websites, including 30.6% of the top 10 million websites as of April 2018, WordPress is the most popular website management system in use. WordPress has also been used for other application domains such as pervasive display systems.   In its early stage, it was prone to constant spam.  As a result it affected the server performance and we abandon it completely.  After that we decided to go with Joomla.

Joomla is an open source platform on which Web sites and applications can be created. It is a content management system (CMS) which connects your site to a MySQLi, MySQL, or PostgreSQL database in order to make content management and delivery easier on both the site manager and visitor.

For more than six years use this CMS ever though server performance was interrupted by poor database & server configuration, vulnerability to hacking.  Not only that, there weren’t enough free modules and components available and the ones that were did not do what we needed.  In addition, the templates cost was too high and they did not work for the type of content we were interested in publishing.  As a result it led to continuous denial of server, poor design, wasted time, resource and money.

By the time we got fed up of the issues, the WordPress CMS was improved and we decided to try it again.  It was by far the best decision we made.  Since the move back to WordPress, we had several free plugins and low cost themes  at our disposal to do what we need to improve traffic consistency.  Although there are several content management systems available today, WordPress is our overall favorite and it receive our highest recommendation.

Database Server: From host machine to remote server

One of the biggest issues we had was the way the database handled the increase in requests.  It was not able to handle it because it shared the resources with other applications like the mail and webserver.  To remedy the issue we decided to move the database server from the host machine to a remote server inside a virtual environment.  This allow for more server resources for the web server and by having its own machine, the database server can be configured for optimal performance.

Webservers: Nginx over Apache

A Web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve the files that form Web pages to users, in response to their requests, which are forwarded by their computers’ HTTP clients.  Dedicated computers and appliances may be referred to as Web servers as well.

The first time I setup my own dedicated server I chose to use the Apache Web server.   Apache is was the most widely used web server software at the time.  It is developed and maintained by Apache Software Foundation.  It is an open source software available for free. It runs on 67% of all webservers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules.  Apache uses Multi-Processing Module (MPM) for handling incoming requests and processes them.  Most WordPress hosting providers use Apache as their web server software.

If you are not familiar with Apache, you will leave the basic configurations in place and that can affect the performance of the server over time.  Up until last year, we were using Apache as our Web server, however due to the lack of understanding of how to configure the server properly for  improved performance, we decided to abandon it completely.

WordPress can run on other web server software as well, therefore in an attempt to find a replacement for Apache we decided to switch to another Web server that was easier to learn, configure and implement, which led us to NGINX.

NGINX is an open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability.  In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers. It accelerates content and application delivery, improves security, facilitates availability and scalability for the busiest web sites on the Internet.  Not only that, it is easy to learn and configure for high performance.
At first, the switch was difficult because the entire server infrastructure relied on Apache and the supporting modules, this includes PHP which was a requirement for WordPress.  While learning about transitioning to NGINX we also learn about PHP-FPM.  PHP FastCGI Process Manager (PHP-FPM) is an alternative FastCGI daemon for PHP that allows a website to handle strenuous loads. PHP-FPM maintains “pools” (workers available to respond to PHP requests) to accomplish this.
In combination, a Web server performance can be improved with both applications running together.  This would replace Apache, MPM and PHP.

Image Optimization: From plugin to server

I must be honest, when I first started configuring WordPress websites, I fell in the trap of plugins.  The advantage of plugins are the fact that they can solve several issues you have on your WordPress site.  However, by doing so you can sometimes sacrifice performance because ill configured plugins can cause more stress on your server.  To solve this issue, consider using server configuration via Nginx GZIP Compression instead of plugins like  Smush or resmushit.  We discover performance and page speed increased significantly when the process is done via the server vice a plugin.

Static File Caching: From plugin to server

The same could be said for Caching, server caching is better than using plugins.  It is common knowledge that caching is a great way to improve page speed load because it takes the stress off the database and deliver pages that are saved in the user browser if it has not expired. In our pursuit of better performance, we discovered using FastCGI caching and Varnish.

FastCGI is a programming interface that can speed up Web applications that use the most popular way to have the Web server call an application, the common gateway interface (CGI).  FastCGI Cache can greatly improve server response time and reduce the load on PHP-FPM process.

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 – 1000x, depending on your architecture.

This means if you have access to your server you will not need to use well documented configurations for plugins like WP Super Cache and W3 Total Cache.

In the end all website owners want is to have a website that runs fast.  It is always a good idea to reevaluate performance on frequent basis.  Another lesson to learn is that plugins do not solve every problem so consider server-side alternatives.  Don’t wait until your website starts to have issues before you consider changing up your options for better optimization.


Like it? Share with your friends!

Staff Writer

FiWEH life staff writers provides breaking news, entertainment, music, videos, fashion, politics and culture Infotainment for the Caribbean diaspora worldwide.
Choose A Format
Personality quiz
Series of questions that intends to reveal something about the personality
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Voting to make decisions or determine opinions
Formatted Text with Embeds and Visuals
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Upload your own images to make custom memes
Youtube, Vimeo or Vine Embeds
Soundcloud or Mixcloud Embeds
Photo or GIF