APIs, Microservices, Code, Beer, and Technical Talks by Mike Moore

WordPress Optimization: Setting Up a Web Server

Welcome to part 3 of 8 on Kick-Ass WordPress Optimization: Setting Up a Web Server!  In this segment we’ll be covering the implementation of a web server on your virtual (or regular) server that we set up in the previous segment or part 2 of 8: Setting Up a Virtual Server.  If you haven’t already done this… you may want to go back and get this going before you end up here.

WordPress Optimization: Web Server Set Up

This segment will cover the following topics:

  1. nginx Web Server – Because I won’t be covering Apache.
  2. Installing PHP
    1. Installing PHP-FPM and Tuning It
    2. Installing PHP Modules
  3. Basic nginx Configuration
  4. Configuring Your Website on Nginx
    1. Generic Configuration Files
    2. Your Main Domain Configuration

So without further ado, we’re gonna dive right in and get you started setting up your very first web server!

nginx Web Server – Because I won’t be covering Apache.

Many of you may have heard of the Apache web server.  This is because it powers more websites than any other web server in the world and has been around since about 1995.  I won’t lie, it’s a great platform with loads of modules and history.  But to this I say: Who cares?  Certainly not us because we’re going with an alternative called nginx (pronounced “Engine X”) and there’s a simple reason why: We’re in this for performance and nginx is an open source web server written to address some of the performance and scalability issues associated with Apache.  So why wouldn’t we do this!?

Alright, first things first: Let’s install nginx!  Go back to your command line as your (not root) user and type the following:

[email protected]:~$ sudo apt-get -y install nginx-extras

This installs the nginx package plus some nice-to-have extras that I like to use and because you’re here following my tutorial… you’re going to use it too! But guess what my friends… that’s it! You have an absolutely basic bare-bones nginx web server running on your machine.  Don’t believe me? Go back to that e-mail or your Digital Ocean dashboard and get the IPV4 address that looks something like this  Copy that into your web browser (I use chrome because that’s what the cool kids are doing these days) and past the address into your address bar and hit enter.  You should see a big fat title that says: Welcome to nginx!

Tada!  That’s all for the basic install folks!  Now, onto some general (but important!) configuration prior to defining your website.

Installing PHP

If you didn’t already know it, WordPress is written in the PHP scripting language, most specifically, PHP5.  If you’d like to read more about PHP, check out the php.net website as I will not be going into detail about what this is.  Knowing that WordPress is written in PHP5, we need to first enable nginx to serve up PHP!  So let’s get started on that.

Installing PHP-FPM:

In order to use PHP5 with nginx, there are a variety of methods.  I, and many others, would say php-fpm (PHP FastCGI Process Manager) is one of the best methods of doing this.  Nice low overhead and it’s fast. So let’s get started.  Go back to your terminal and type:

[email protected]:~# sudo apt-get -y install php5-fpm

This will get very basic and unoptimized php5 and php-fpm installed. So let’s tune it up a little bit to take advantage of the speed potential.  We’re going to have to edit the configuration files a little bit, so go back to your command line and type the following:

[email protected]:~# sudo nano /etc/php5/fpm/pool.d/www.conf

This will open up the PHP-FPM pool configuration file.  The pool is going to be a collection of “listeners” waiting to run WordPress (and other) PHP code that gets sent to it by nginx.  Scroll up or down in the file (Page Up / Page Down) to find the following lines and make sure they match.  If they don’t, change them!  When you’re done, use Ctrl+O, check the file name, press Enter, and then Ctrl+X to close.

listen = /var/run/php5-fpm.sock
listen.allowed_clients =
pm = ondemand
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 100

These values will allow your PHP-FPM instances to run quickly, on-demand, and securely!

Next Post

Previous Post

© 2018 Web of Mike

Theme by Anders Norén