Host a WordPress Website with SSL for free on Google Cloud

Ariel Filotti
Zencore Engineering
6 min readMay 12, 2023

Google Cloud is a powerful cloud computing service that offers a wide range of capabilities. Among these is the ability to host a WordPress website that can handle a respectable volume of traffic. All you need to get started is an internet domain for creating DNS records.

In this tutorial, we’ll walk through the process of setting up a free Google Cloud account, deploying a VM with WordPress, and configuring the server to secure a free SSL certificate from Let’s Encrypt. By the end, you’ll have a fully functional, secure, and free WordPress website live on the internet. Let’s get started!

To access Google Cloud, you need a Google Account. This could be either your Gmail account, or you can create a Google Account with your company email address. Then you can access this URL to open the Google Cloud console:

https://console.cloud.google.com/

Next you will need to create a Project. In Google Cloud, Projects are a way to group your cloud resources. To create a Project, open the left side menu, then go to “IAM & Admin”, and then “Create a Project”.

Give your new Project a name, or accept the default one, and then click on “Create”. You will soon be taken to the dashboard for your new Project.

Open the left menu, and then go to “Compute Engine”, and then “VM instances”.

You will be prompted to enable the Compute Engine API. Click on the “Enable” button. At this point, Google will ask you to provide billing details to verify that you’re not a bot, but you won’t get charged if you deploy the resources described in this post.

Now we’re going to create our free WordPress VM. From “Compute Engine”, and then “VM Instances”, click on the “Create Instance” button.

Type a name for your new VM, and then make sure you select one of the regions that are eligible for the free tier. You can select any zone within these regions:

  • Oregon: us-west1
  • Iowa: us-central1
  • South Carolina: us-east1

Select the e2-micro machine type. At the time of writing this post, the default image is Debian 11, so I will use that one.

Change the boot disk to Standard Persistent Disk and increase the size to 30GB, as those are the settings included in the free tier.

In the Identity and API Access section, I would recommend that you set the Service Account of the VM to “No service account”, unless you’re familiar with how Service Accounts work in GCP and can create a new one with only the necessary permissions. The Compute Engine default service account has too many privileges and it’s dangerous to use it in a public facing VM.

In the Firewall section, allow HTTP and HTTPS traffic. Then click Create to deploy the VM, and once it’s ready, click on the SSH button to open a shell.

Install PHP and some of the most common extensions. This will also install the apache web server and the MariaDB database server (equivalent to MySQL).

sudo apt update && sudo apt install php php-common php-mysql php-gmp php-curl php-intl php-mbstring php-xmlrpc php-gd php-xml php-cli php-zip mariadb-server

Now we will create the database and the user for the WordPress application. Run the following command to open the MariaDB shell:

sudo mysql

If the connection to the database was successful, run these SQL statements, replacing the password (GoogleCloudWordpress) for a secure one:

CREATE DATABASE wordpress;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'GoogleCloudWordpress';
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT

Now let’s download the latest version of WordPress and install it. This will be the first and only time that we install WordPress from the shell, as future updates will be installed from the WordPress admin panel.

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress/* /var/www/html
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/html/
sudo rm /var/www/html/index.html

To access the website, we’ll need a domain. Unfortunately, there aren’t a lot of ways to get a free domain, so you’ll probably need to pay for one. Once you purchase your domain, you’ll get some kind of control panel that allows you to create DNS records.

Create an A record in your DNS control panel that points to the public IP address of your VM. You can get the IP address by looking at the details of the VM in the GCP console.

Once you have the DNS record set up, we can install the certbot package in the VM and enable it for the Apache web server.

sudo apt install certbot python3-certbot-apache
sudo certbot --apache

It will ask for an email address and the domain name. And then, if the DNS record of your domain name is already pointing to your public IP address, it will validate and issue the certificate.

At this point you should be able to access your WordPress installation in your browser, by opening https://yourdomain.com. You should get the WordPress installation wizard. If you followed these instructions, then fill out the details like this:

On the next step, you can define your site name, and create a user and password for administering the site. After you finish the installation, you can log in to the WordPress admin panel.

So, what kind of performance can we get from this free website? I ran a loader.io test without making any optimizations in WordPress:

As you can see, the site struggles under load, and there are a lot of requests that timed out. So how can we improve the performance of the website?

There are some free plugins for WordPress that can improve our performance with the proper configuration. In the WordPress admin panel, go to Plugins, and then Add New. Search for the “wp-optimize” plugin and install it.

After the installation is complete, click on “Activate”, and then on the “Optimize” link below the plugin name.

Now go to the Cache tab and turn on page caching:

Then go to the “Minify” section and enable Minify.

Now we’ll run the load tests again, and we can see that performance is much better now, and the server is able to handle 100 simultaneous clients.

Congratulations, you’ve now successfully set up a free WordPress website on Google Cloud! By leveraging the power of Google Cloud’s free tier and the versatility of WordPress, you have created a platform that can support your online presence. You’ve also ensured your site’s security with an SSL certificate from Let’s Encrypt and optimized its performance with the WP-Optimize plugin.

Now, you have the freedom to customize your website to your liking. You can add engaging content, install other useful plugins, and tailor the design to fit your brand or personality.

Remember to always keep your WordPress installation up to date, including any plugins that you might have installed. This will provide protection against future vulnerabilities in the software.

In the future, if you find your website needs growing, remember that Google Cloud Platform offers a wide array of scalable solutions to meet those needs. Whether it’s increasing storage, handling more traffic, or even integrating AI capabilities, Google Cloud can accommodate you.

--

--