Stories

How To Setup Fastest Hosting Server For WordPress Website

WordPress (WP, WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes. WordPress was originally created as a blog-publishing system but has evolved to support other types of web content including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores. WordPress is used by more than 60 million websites, including 33.6% of the top 10 million websites as of April 2019, WordPress is one of the most popular content management system solutions in use. WordPress has also been used for other application domains such as pervasive display systems (PDS)

As per one report in 2020, WordPress powers more than 40-45% Internet websites as main cms and almost 90% websites as their blogging tool on subdomain or directory.

Now it is pretty obvious that WordPress is the most used CMS in the Internet world.

Like everything has its pros and cons, there are certain cons associated with WordPress. WordPress is very resource hungry. The more content you add, the slower it will get due to excess of the database query.

Today we are offering a very well researched process of setting up the WordPress based website on which Inventiva team has done very extensive and deep research for more than three months.

This entire setup will not take more than 10-30 minutes depending on your internet connection, typing speed and understanding skills.

1. Take the hosting server or VPS from OVH or any company of your choice like digital ocean, vultr, linode, ramnode, hetzner or scaleaway etc

Why we have mentioned OVH is because of their amazing pocket-friendly pricing, their infrastructure and their extensive customer support.

OVH is the world third largest datacenter and hosting company behind Google & Amazon, But their products are much better with better hardware and amazing prices.

Amazon cost is very high and setup is very messy and too much of cluttered, google hardware is not upto the mark. Especially to mention here, OVH is the company which can handle DDOS attack much better than any other company in this whole world. They have the superior infrastructure and internet backbone, presence in many continents with one of the largest number of servers. The company also has the best SLA and uptime guarantee.

2. HestiaCP

HestiaCP is the better, more modified, more secure and more robust fork of very famous vestacp. Vestacp dropped their development somewhere around 2018 and hence the hestiacp took birth. The team behind hestiacp are hardcore full stack developers and they have done every bit to make it more userfriendly, secure and robust. The design of hestiacp is very neat and clean and their upgrades are very amazing, they do test every part of their web panel before launching it for public use.

3. Cloudflare

Once you buy the OVH server or vps, install the latest Debian 10 on the same. Debian is the most used distro for web servers, almost 65% web servers in this world are powered by Debian, debian is also the base for Ubuntu which is an amazing os for desktops, for servers Debian is prefered, their updates are stable and is very secure.

login to your server via ssh and run the following commands

apt-get update && apt-get upgrade – This will update and upgrade all the packages

apt-get dist-upgrade – This will upgrade your distro

apt-get update && apt-get -V upgrade- this will check the versions and run update

sudo apt autoremove- this will remove any unwanted packages from the server

sudo apt autoclean- will clean the server


Download the HestiaCP installer:

wget https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh

Run the installer and follow the prompts:

bash hst-install.sh

For Custom HestiaCP installation, visit the link https://gabizz.github.io/hestiacp-scriptline-generator/ and generate the install script by yourself.

In our case the install script was

sudo bash hst-install.sh –apache no –nginx yes –phpfpm yes –multiphp no –vsftpd yes –proftpd no –named yes –mysql yes –postgresql no –exim yes –dovecot no –clamav no –spamassassin no –iptables yes –fail2ban yes –quota no –api yes –force no –interactive yes –port 8083 –hostname domain.com –email [email protected] –lang en

We have removed Dovecot, SpamAssassin, ClamAV etc but We have still kept exim to get basic notifications from the server and transfer user registration details to our teams, you can avoid installing Exim also and use SMTP providers like SendGrid, mailjet, Sendinblue, sendpulse. Our choice was sendinblue- they have a very clean interface, 300 emails per day free, plus their integration is very friendly and easy to do. The email delivery is also very amazing and almost 95% of their emails land into the primary inbox of google, yahoo, hotmail-outlook.


For A Better, Faster Server always keep the services on the server to very low

We have avoided installing apache, multiphp, dovecot, ClamAV, SpamAssassin on the server.

You only need dovecot if you want to have your emails also on the same server where you want to host your website, emails take lot of space hence it is always suggested to have the emails hosted either on Google Apps or Zoho. Our choice is zoho

 

Always keep the server behind a CDN for fast delivery of your pages and content, there are tons of CDN available right now in the market like

Cloudflare
MaxCDN
BunnyCDN

Our choice is Cloudflare, Cloudflare is not just a CDN, it is a plate full of many other services which you won’t find with other services like

Free SSL
Free DNS
Free Caching
HTTP/3
Analytics
Minify

In terms of Server location, Cloudflare is ranked number 1 with their presence in the entire 6 continents and their servers are really fast, they also have the largest number of servers spread across every major location you can think of thus giving your website ultimate speed.

Our choice of Cloudflare is also for a very specific reason which we will mention in the article below.


Once you install the hestiacp, login to the hestiacp on web browser

http://ipaddress:8083

Add your domain and customize the package as per your need.


Login to the putty once again and run the following command


cd /home/admin/web/domain.com/public_html/

rm -vrf *

wget https://wordpress.org/latest.zip

unzip latest.zip

mv /home/admin/web/domain.com/public_html/wordpress/* /home/admin/web/domain.com/public_html/

chmod 777 -R /home/admin/web/domain.com/public_html/


Do not forget to replace domain.com with your own domain.


Also, create a database and its user in hestiacp admin panel and note down the details

Visit your domain www.domain.com in the front using a web browser and install WordPress using the database details.


Once you setup the WordPress you can login to the admin panel and I am sure, you already love its speed on your newly setup server.


To Further work on its speed you need to keep following points in mind.

1. Always keep the wordpress plugins installation very very low.

2. Always upload optimized images which are less in size, uploading the images of 2-10 MB in size makes no sense, always keep the image size not more than 250KB


You can setup various cache on your website explained as below

1. NGINX fastcgi cache- Nginx includes a FastCGI module which has directives for caching dynamic content that are served from the PHP backend. Setting this up removes the need for additional page caching solutions like reverse proxies (think Varnish) or application specific plugins. Why we have avoided varnish is simple because varnish do not serve on HTTPS, so you again need to go in lot of technicalities to serve Varnish pages on https which is not worth.

NGINX FastCGI Cache was the fastest and the most efficient caching solution of the lot. If your website do not have too many mysql querries then this is the best cache to setup.

What is Nginx FastCGI Cache
Before we talk about Nginx FastCGI Cache, let’s talk about how your website works.

When a user visits your WordPress page, the web browser sends an HTTP/HTTPS request to Nginx.
Nginx passes the request to PHP-FPM and Nginx will catch any PHP codes when trying to grabbing the page.
PHP-FPM processes the page and runs through the MariaDB/MySQL database query to retrieve the page.
PHP-FPM sends the generated “static” HTML page back to Nginx.
Nginx send the generated HTML page to the web browser for the user.


1.Configure NGINX to enable FastCGI caching
To set this up we will need to make a few changes to our NGINX server block. We are currently using the default virtual host file, so we should open the default configuration file:

sudo nano /etc/nginx/sites-available/default

In this configuration file enter the following lines above and outside the server{ } block:

fastcgi_cache_path /var/run/nginx-fastcgi-cache levels=1:2 keys_zone=FASTCGICACHE:100m inactive=60m;
fastcgi_cache_key “$scheme$request_method$host$request_uri”;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;


Next enter the following directives within the PHP location block:

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache FASTCGICACHE;
fastcgi_cache_valid 60m;
add_header X-FastCGI-Cache $upstream_cache_status;

Once you have saved and exited the file don’t forge to check that your NGINX configuration file is syntax error free with the following command:

sudo nginx -t

Assuming everything is okay, restart the NGINX server.

sudo service nginx restart


2.Install a WordPress NGINX Caching Plugin
The last thing we need to do is install a WordPress NGINX caching plugin to automatically purge the FastCGI cache whenever your WordPress site content changes. There are several of these plugins to choose from, but we will go with another plugin by Till Krüss, NGINX Cache plugin.

Search for this plugin in the repository, install and activate it:

There is another NGINX cache plugin with the name NGINX Helper which is a complete piece of shit.

 

2. Redis cache- Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

Redis cache is mostly used where your website has lot of database querries for eg- if you are running a social media website, ecommerce website, chatting website, dating website where you have lots of users who perform multiple task at a very high number after logging in and there are too many mysql querries to be performed every single minute.


To install Redis, issue the following commands.

sudo apt install redis-server
sudo service php7.4-fpm restart

Redis can operate both as a NoSQL database store as well as a cache. For this guide and use case, Redis will be configured as a cache. In order to do this, the following settings are required.

Edit the file /etc/redis/redis.conf and add the following lines at the bottom:

sudo nano /etc/redis/redis.conf
Add these lines at the end of the file:

maxmemory 256mb
maxmemory-policy allkeys-lru


In order for WordPress to use Redis as an object cache, you need to install a Redis object cache plugin. Redis Object Cache by Till Krüss is a good choice.

Once installed and activated, go to Tools > Redis to enable the object cache.

If your server doesn’t support the WordPress Filesystem API, you have to manually copy the object-cache.php file from the /plugins/redis-cache/includes/ directory to the /wp-content/ directory.

To avoid conflicts when hosting your WordPress site, add the following lines to the wp-config.php file:

At the very top, just below the <?php tag on the top of the file, add this:

define(‘WP_CACHE’, true);
And, at the first line on the Salt Keys Section of the file, add this:
define(‘WP_CACHE_KEY_SALT’, ‘yoursite.com’);

The WordPress Cache Salt Key (yoursite.com in the example above) could be anything you like. It must be a unique key for every WordPress install on that server. This way we are sure Redis properly handles it. Using each install domain is the recommended option in this process.

In our case, we are running a static content driven website where we do not allow visitors to login to the website and perform any task, they simply visit the website, read the news, like or share and gone.

In our case, we have only used nginx fastcgi cache for the same.


If you want to avoid all this editing and coding mess there are more options for you, use cache plugins like

1. WP Super Cache, WP Fastest Cache, W3C Total etc.

Our choice is wp super cache because it is been built by the internal teams who have made wordpress so they understand wordpress much better than anyone else, second its installation and setup is very easy, almost like cutting the butter with hot knife.

2. There is another amazing plugin which is WP Cloudflare Super Page Cache

Now this plugin is absolutely an amazing plugin which uses the cache power of Cloudflare and its page rule, just install the plugin and it will handle everything all by itself, do not forget to integrate the plugin with cloudflare and it setup page rules of cloudflare and everything by itself.

You can also use some more plugins to further optimize like wp-optimize to optimize the database as well as autoptimize to optimize its CSS and JS files but that wont be needed as long as you are using cloudflare, cloudflare has an internal minify system which serves your pages with better optimization.

Remember, the more plugins you install in wordpress, more slow it will be. So avoid multiple plugins installation else your website will become more slow instead of getting fast.


Finally I am sure, after running this entire setup, you will be able to see a drastic improvement in your wordpress website speed and its performance, the entire setup not just improves your wordpress website speed at the frontend but also at the backend.

You will find the backend running at a better speed, more smoothly and performing task at a rapid speed.


** From personal observation and choice, I very strongly feel that you won’t need any caching plugin with HestiaCP pure NGINX installation, I have just simply installed HestiaCP with NGINX on a bare metal server taken from OVH and never installed any cache plugin or did anything to control cache and my server is able to hold almost 50,000 co-current connections without any modifications and this all has been personally tested by me and team of Inventiva, the website opens amazingly fast and perform all the task at speedy rate without any issues.

In order to get A++ rating from QUALYS SSL Labs, you can buy COMODO ssl certificate from SSLS.com, Comodo SSL is a trustworthy name in the cyber security since more than two decades, they offer very effective and pocket friendly SSL certificates.


Note: We are not promoting any services through this article, neither we have added any affiliate links for making the money nor this article is sponsored

All the above configuration have been extensively tested by our own internal team after a hardwork of more than 3 months and continuously studying more than 7-8 open source web control panels.

This article is written purely with a pure and sole intention of helping other fellow people who are looking to run their own websites and are struggling with web architect and its scalability, speed, strength to handle and tackle the web traffic maintaining its speed.

Our Case: Inventiva website is built using HestiaCP pure NGINX installation over the dedicated server taken from OVH, Protected By Cloudflare. We have no cache plugin installed and this website is able to take a load of 70-75K co-current visitors as tested by online load testers. 

Related Articles

Back to top button