A step-by-step guide to convert WordPress (WP) into a static site and host them in Google Cloud Storage (GCS).
Running massive traffic WordPress sites is challenging. There are many factors:
- Expensive – require server(s) based on the size of the traffic
- Skills – you must be skilled in optimizing web server, database, PHP, WP for optimal performance.
- Security – have to ensure necessary WP related security is implemented to avoid being hacked.
- Maintenance – you need to regularly updated WP core, themes, plugins to ensure doesn’t expose any vulnerability or break because of compatibility issue.
A static site is lightweight, and security is less concerned.
You can get the static site running on cloud storage like GCS and pay for just storage/bandwidth cost (much lower compare to WordPress server).
I know what you are thinking.
Making site with WordPress is easy as it got large themes and plugins marketplace. You can make your site ready with WP in just a few minutes/hours, which will take longer to design/develop using static HTML/CSS/JS.
So how do you not leave WordPress and enjoy static site benefits, together?
Well…
The idea is to use WordPress to build your site and, once done, convert them into static HTML files.
Let’s see how to do it efficiently.
Exporting WordPress to Static HTML Files
There are many ways to achieve this, but I found the following procedure is straightforward. As usual, try in a staging/non-prod environment first to see how it works.
- Login to your WordPress Admin
Note: if you don’t have a WP setup yet, then you may set up the LAMP environment on your local PC or use shared hosting like SiteGround.
- Go to Plugins >> Add new
- Search for “Simply Static” and install >>activate
- On the left navigation, go to Simply Static >> Settings
In most cases, you can leave all settings default, but take a look and see if you need to include or exclude any URL manually.
- Go to Generate and click “Generate Static Files.”
It will take some time based on the size of your site. I am testing with some dummy installation, which got 56 URL and took 5 seconds.
- Download the zip file by clicking “Click here to download.”
This concludes WordPress site is converted into static files, and it’s time to put them in Cloud Storage.
Update: I came across another two solutions which help to make WordPress site static too.
- HardyPress – provide an option to convert existing or create a new site. It provides hosting as well.
- Shifter – Serverless WordPress hosting.
Hosting WordPress Static Files to Google Cloud Storage
GCS is one of the best cloud-based object storage to host static files. But there are more if you would like to explore.
I got one spare URL (techpostal.com), which I will be using for this demonstration.
First thing, you got to verify the domain ownership with Google.
Once verified…
- Go to Google Cloud >> Storage (direct link)
- Click create bucket
- Enter bucket information and storage class and create
- Go back to the browser
- Select the drop-down next to the newly created bucket and select “Edit website configuration.”
- Enter the main page –
index.html
- Select the drop-down again and go to “Edit bucket permissions.”
- Enter allUsers in add members >> select role as Storage Object Viewer and click Add
- Go back to the browser and upload the extracted zip file which you downloaded in previous steps
Next, you need to update your domain record to point to cloud storage
- Login to your Domain registrar panel and update CNAME record of your domain to c.storage.googleapis.com
- Wait for few minutes and check DNS record to ensure it’s resolving to the configured one
Verification
and finally, let’s access the URL
So as you can see, it works.
BTW, if you want to implement SSL, then you can refer to this guide.
There are a few limitations to be aware of. The static site won’t be able to do certain things like WordPress.
Ex:
- Comments submission
- Opt-in forms
So if you heavily rely on those, then this may not be a good solution; however, if you are using WordPress site as an information page, startup, personal, then it’s worth giving a try.