In this tutorial, I will show you how to set up a superfast and high-performance WordPress blog with php 7.2 and nginx microcaching on ubuntu 16.04 / Debian 9 server.

What is Nginx Microcaching?

Microcaching is a method of caching dynamic content for a short period of time, Benefit of this method is Improved page load time and reduces server load on high traffic spikes.

VPS I am using:
Debian 9.3
1 CPU
2GB RAM
20GB SSD

This is the cheapest VPS available at https://www.hetzner.com/cloud

1. Update the system and install necessary packages

sudo apt -y update && sudo apt -y upgrade
sudo apt install apt-transport-https lsb-release ca-certificates wget git

2. Install MariaDB

sudo apt-get install mariadb-server

When the installation complete, run the following command to secure your DB Server

mysql_secure_installation

Now create mysql database and user for wordpress
mysql -u root -p yourmysqlpassword
CREATE DATABASE wpdb;
GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
FLUSH PRIVILEGES;

3. Install Nginx

curl http://nginx.org/keys/nginx_signing.key | apt-key add -

sudo sh -c 'echo "deb http://nginx.org/packages/debian/ $(lsb_release -sc) nginx" > /etc/apt/sources.list.d/nginx-latest.list'

sudo apt update

apt-get install nginx

4. Install the latest version of PHP 7.2 and all necessary modules

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

sudo apt update

sudo apt install git php7.2-common php7.2-readline php7.2-fpm php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-mbstring php7.2-opcache php7.2-json php7.2-xml

5. Nginx Configuration

In this part we are going to use a forked version of Ashley Rich’s Nginx server configurations, It contains the best practices from various sources, including the WordPress Codex and H5BP.

Note: From now onwards you have to replace ‘linuxsuperuser.com‘ to your blog name in below commands

Create home directory for your wordpress installation
mkdir /var/www/linuxsuperuser.com/

Backup any existing nginx config
sudo mv /etc/nginx /etc/nginx.backup

Clone the repo of nginx configurations
sudo git clone https://github.com/shyamjos/wordpress-nginx-microcache-setup.git /etc/nginx

Symlink the default file from sites-available to sites-enabled, which will setup a catch-all server block. This will ensure unrecognized domains return a 444 response.

sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

Copy example configuration from sites-available

sudo cp /etc/nginx/sites-available/fastcgi-cache.com /etc/nginx/sites-available/linuxsuperuser.com

make necessary changes to config file accordingly, paying close attention to the server name and paths.
sudo nano /etc/nginx/sites-available/linuxsuperuser.com

symlink the configuration into the sites-enabled directory
sudo ln -s /etc/nginx/sites-available/linuxsuperuser.com /etc/nginx/sites-enabled/linuxsuperuser.com

6. Test the nginx configuration for any syntax errors

sudo nginx -t

7. Create necessary directories and log files

mkdir /var/www/linuxsuperuser.com/logs
mkdir /var/www/linuxsuperuser.com/cache
mkdir /var/www/linuxsuperuser.com/public
touch /var/www/linuxsuperuser.com/logs/access.log;
touch /var/www/linuxsuperuser.com/logs/error.log;

8. Download and extract wordpress

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
cd wordpress
mv * /var/www/linuxsuperuser.com
chown -Rf www-data:www-data /var/www/linuxsuperuser.com
nginx -t
service nginx restart

9. Complete the wordpress Setup

Now head over to your domain name and complete the wordpress setup
Voila! Thats it , Your superfast wordpress blog is ready.

Setup A Superfast WordPress blog with PHP 7.2 and Nginx Microcaching
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: