Hi, As we all know, hosting a WordPress site is easy but optimizing it to load faster with the minimum bugs is not a bad of roses.
Today, we are going to install LEMP stack on Ubuntu 18.04 + Varnish cache to facilitate the fastest loading speed.
Deploy the server from anywhere. Just make sure that you have ubuntu 18.04 droplet. It can be Google cloud, Vultr, DigitalOcean or any other VPS provider.
LOGIN as root in putty, terminal or browser SSH terminal.
Start with the commands below.
You will see a line cgi.fix_pathinfo=1, if the line is quoted, remove the quote and replace ‘0’ with ‘1’
Now, the server is setup. Lets install PhpMyadmin
Lets link to Phpmyadmin
Do not panic if the above command does not work. Let’s move the next.
Let’s change the phpmyadmin dashboard location
Our PHPMyAdmin is also setup Now.
So far, we have installed Nginx, PHP 7.2 fpm and phpmyadmin on the Ubuntu 18.04.
Now is the time to access your MySQL through SSH and create database, user and grant all permissions.
LOGIN to your server as root and enter the mysql-
Enter password and hit enter.
Lets create a database (below are SQL commands)
Now is the time to login to your database through the phpmyadmin console.
I will use FileZilla to upload the WordPress files in the document root directory of the server.
Download WordPress
- Edit the wp-config.php
- Archive the whole WordPress
- Rename it to wordpress.zip
- Upload it to /var/www/mydomain
I am back on the SSH terminal Now and I will install zip unzip on the server.
Navigate to the document root and unzip the file here.
Your server stack is all set to host the wordpress website.
- Open http://mydomain.com
- WordPress Installation wizard opens
- Fill up the required fields and run the installation
Next – Install Varnish Cache on Nginx server
After successful installation your Nginx server Line 4should be listening on port 80. Varnish on Lines 6,7is using both 6081 and 6082 ports.
In the default hosting block, the server should listen to port 8080
Save the file and exit.
Nginx should now be listening on new default port 8080 as shown on Line 4 from the ss command output:
If you want to replace the normal Nginx default page to a varnish default page, run below command. (optional)
Edit Line 9 and change default port 6081 to port 80 as shown bellow:
Instructing Varnish to rely on nginx.
The file should have port set to 8080. (check and set port to 8080 if it is 80.)
All set! Lets reload the Nginx server.
TESTING VARNISH CACHE
It may ask you to first install curl. Run the below command if you see such error.
The response should look something like this:
Your site is on one of the fastest WordPress server stack. Enjoy!
Cheers…..