Converting a WordPress website to static HTML provides various benefits like speed and security. As WordPress powers almost 43.2% of the internet and has many advantages over other CMS, it has 2 critical drawbacks. First, it’s slow, and second, it’s open to attacks.
To overcome these drawbacks it is often suggested to convert WordPress sites to Static HTML sites. Few suggest using static site generators like Jekyll, Hugo, Eleventy, and others (A great list of Open-Source Static Site Generators by It’s FOSS).
While the above platforms are good alternatives, one might still prefer to use WordPress and want the benefits of a static website, don’t worry we got you covered.
Table of Contents
Moving WordPress to a staging environment
You might be thinking why should we move WordPress to a staging environment?
It’s not necessary to move it to a staging environment but it’s recommended. If we keep WordPress on the same server which has the HTML file, then one of the advantages of a static website i.e. lesser area for attack (more secure) won’t be valid as WordPress will still be open to attacks.
So in this tutorial, we will move our WordPress site to a staging environment.
What staging environment can be used:
- A different server that can only be accessed by you or
- Your local computer (which I use personally)
I host my WordPress locally as it is more secure to host it on my PC (it’s not available online to attack but you need to be careful and keep proper backups)
Steps we will follow to migrate:
There are many plugins available for migrating your WordPress website like Updraft, Duplicator, All-in-One WP Migration, and many others or you may do it manually.
Details of migrating are out of the scope of this article so you may follow one of the following guides:
- Migrating a WordPress Site with the WordPress Duplicator Plugin
- How to Manually Move a WordPress Site
I used the Duplicator plugin to migrate my website and it took me 5 mins. Please keep in mind, to host it locally you will need a server running on your computer.
I have a LEMP stack (Ubuntu, Nginx, PHP, and MariaDB installed on my computer) to run my WordPress locally.
How do I access my local install?
Just type “localhost” in any browser and you will be able to access it. WordPress admin URL will be “https://yadavgaurav.com/wp-admin”
Now we have a locally hosted WordPress and we will generate a static copy of the website, which we will be deploying on our live server.
Generating Static Copy of WordPress
We will be using the WP2Static plugin to create a static HTML copy of all the posts and pages of our website.
WP2Static is developed by Leonstafford and is not available in the WordPress plugin directory. So you need to download it from GitHub or WP2Static website.
Once you download the plugin, install it by uploading it to your website. Now open the WP2Static menu and you will see the “Options” tag under the menu. Now at the end of the page, there will be “Post-processing Options”, under which we need to set the “Destination URL”. Set the destination URL to your website URL, In my case, it is “https://yadavgaurav.com”.
Under the menu, the first option is “Run”, which will open a new , you will see “Generate static site” Click it to generate a static copy for your WordPress website.
Deploying the Static version to production or live server
Now we have a static copy of your website which can be found at “/var/www/html”. Static HTML can be found in the wp-content/upload folder.
Please keep in mind that 2 folders “wp2static-crawled-site” and “wp2static-processed-site” can be found in uploads. We need to use the contents of the “wp2static-processed-site” folder and not of the “wp2static-crawled-site”.
Now connect to your live server, I’m using DigitalOcean droplet so I use Filezilla to SSH/connect to it and upload all the contents of “wp2static-processed-site” on it.
No further steps, our website is live and ready to be served.
Leave a Reply