In this tutorial, you will learn how to host a free website on Google Cloud Platform. This is possible on the Google Cloud Platform free tier.
By the end of this tutorial, you will have a fully-functioning WordPress website running on an Nginx web server. Let’s get started.
Get $300 Free Google Cloud Credits
Note that if you find Google Cloud hosting too complicated, there are many other ways to host a free website.
1. Create a Google Cloud Platform Account
First things first. Create yourself a Google Cloud Platform (GCP) account. This video will walk you through the process of setting up your GCP account if you don’t already have one.

2. Spin Up a Compute Engine VM on the Free Tier
From the GCP dashboard, click on Compute Engine. Create a VM instance.
In order to create your VM instance on the free tier, you must configure your VM with the following restrictions:
- Non-preemptible f1-micro VM instance
- US regions: Oregon (us-west1), Iowa (us-central1), or South Carolina (us-east1)
- Up to 30 GB-months HDD
Notice how it says “Your first 744 hours of f1-micro instance usage are free this month”. This number will vary depending on how many days are in the current month. For example, this screenshot was from October which has 31 days.
31 days x 24 hours = 744 hours
Feel free to choose any operating systems for the boot disk. In this tutorial, I chose Ubuntu 20.04 LTS.
Get $300 Free Google Cloud Credits
3. Connect your Domain Name (optional)
You can optionally associate a domain name with your IP address. If you don’t have a domain name, feel free to skip ahead to the next step.
Otherwise, you can use create a DNS A record at your domain registrar with a value of the IP address of your Google Cloud Platform VM instance.
In Google Domains, for example, you can add the DNS A records for your domain name. The screenshot assumes the IP address of your VM instance is 35.222.110.120.
It can take up to 48 hours for your domain name to become associated with your IP address, but it usually happens within a few minutes.
4. Login to Your Server
You have a few different options for logging in to your VM instance. The easiest way is to select the “Open in browser window” which will log you in to your VM instance without the need to provide any credentials.
You can also use the gcloud command to log in via the command line or terminal.
5. Update Your VM
Once you’re logged in to your server, the first thing you want to do is update your system.
sudo apt update sudo apt upgrade
6. Install the Web Server, Database, and PHP
Use the apt package manager to install the Nginx web server, Mariadb database, and PHP.
sudo apt-get install nginx mariadb-server php-fpm php-mysql
7. Setup the WordPress Database
First, secure your database installation. After executing the following command, answer Y
for each security configuration option.
sudo mysql_secure_installation
Create a database and user with appropriate privileges for WordPress. Access the MySQL command prompt by simply typing mysql
.
create database example_db default character set utf8 collate utf8_unicode_ci; create user 'example_username'@'localhost' identified by 'example_password'; grant all privileges on example_db.* TO 'example_username'@'localhost'; flush privileges; exit
8. Install WordPress
Next let’s download and install the latest version of WordPress from the official website.
cd /var/www sudo wget https://wordpress.org/latest.tar.gz sudo tar -zxvf latest.tar.gz sudo rm latest.tar.gz
Also, change the owner and group of the WordPress root directory to www-data.
sudo chown www-data:www-data -R wordpress/
9. Configure Nginx to Serve Your WordPress Website
Make a configuration file for your WordPress website at /etc/nginx/sites-available/example.conf
with the following content adjusted accordingly for your website. Of course, feel free to name your configuration as you see fit.
upstream example-php-handler { server unix:/var/run/php/php7.4-fpm.sock; } server { listen 80; server_name example.com www.example.com; root /var/www/wordpress; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass example-php-handler; } }
You will need to change the server_name option to your domain name, or if you don’t have a domain name, simply change this line to server_name _;
.
Also, depending on what version of PHP was installed, you may need to update line 2 to the actual version of PHP that’s installed on your server.
Finally, publish your website by making a symlink from your sites-available/example.conf
file to the sites-enabled
directory.
sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
You will also want to remove the default Nginx config file like this.
sudo rm /etc/nginx/sites-enabled/default
Test your Nginx configuration changes and restart the web server.
nginx -t systemctl restart nginx
10. Setup WordPress
Navigate to your IP address or domain name (in this case example.com) and you’ll see the famous five-minute WordPress installation process. In reality, it take about a minute to fill out this form.
Give your website a title, username, and secure password.
After clicking on the Install WordPress button, you’ll have a brand-spanking new copy of WordPress on your web server. Feel free to pick out a theme (I recommend GeneratePress), write some blog posts, and make your website fast with caching plugins.
If you want to make another WordPress website, you can follow this tutorial that will teach you how to host multiple WordPress websites on a single server. This won’t incur any additional charges on Google Cloud Platform, but please be aware that you are limited to 1 GB of network egress per month. If you don’t know what this means, I explain it all in this video.
Other next steps include installing an SSL certificate on your server to enable HTTPS and make your website secure.
Any questions, let me know in the comments below.
Get $300 Free Google Cloud Credits
Next, check out some of the many other ways to host a free website.
Tony your work is amazing, your method to deliver knowledge is very simple. The best thing about you i like is the shortest videos. Straight to the point.
Thank you very much 🙏
Great tutorial. And i did it too ^^
My opinion, in this tutorial need to add “sudo mysql -u root -p “.
Actually i stuck for a moment after step7. and watching Youtube tutorial and “sudo mysql -u root -p” was there.
And one more thing.
It is not a good question. but i want to add subdomain thing.
mydomain/sub (this index is index.html) how can i get this work?
just add files to mydomain/sub and browser gets Forbidden error.
Owh i did it.
mydomain/sub folder was no access right.
And i set access sudo chmod 777(full) mydomain/sub then get no error and it works.
maybe 777(full) is not neccessary.
Hi Tony or anyone that can help…
I’m almost at the end and just a little confused with sending the link from sites available to site directory sudo ln -s command..i get this message: missing file operand… Am i suppose copy and paste the whole link: sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/ or paste the link with my domain name in the place of example.conf or just type the command sudo ln -s and the link with my domain name will show up?
Thank you,
Claudia
Hi Claudia. If you followed the tutorial step-by-step, you can copy the command as it is on this page. If not, just make sure to use the name of your configuration file and make sure these paths exist on your system.
what about Enable SSL , The Site Still Not Secure
You can use Let’s Encrypt to automatically issue a free SSL for your website. While this video is not specifically about Google Cloud Platform, you can follow the steps to enable SSL.
What if you just want to do a php website. Also will this site be recorded as https?
Sorry kinda newbie
You can certainly do a pure PHP website and skip the WordPress steps.
If you want to enable HTTPS, you can install a free SSL certificate. I have a video specifically about this here https://youtu.be/uSm3xepvUNM
Thanks for all!
its works with me, thanks!
Hi Tony, thanks for the great effort. With the apache server, wordpress works. However with the nginx server, I got the html page of nginx..rather than the sub-directory /wordpress/ residing in the same directory folder with the html..which is /etc/nginx/www/ ? Is there something in the *.conf file that should be included ..because root was already disabled earlier.. ? Or should I just move the whole wordpress files into the html folder???
Hi William. Please try the following:
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
This will remove the default nginx config file so that the only config file is the wordpress one that you created.
After doing the delete, now I got this message “502 Bad Gateway” and below this text, shows “nginx/1.14.2
William, please see if my suggestions in this video help you out https://youtu.be/hYVriHb43wU
Yes, I changed to root privileges, with su -i, amended the “default” files which contains a whole list of # out lines…but just delete the hex # sign from those lines similar to your video. Re linked the sites-enabled…and this time it goes to the Wordpress set up page…
Thank you for taking the trouble to go through this with me. Truly appreciate it.
Hi Tony,
Thank you for such a detailed step by step tutorial. It works great!
All was well until recently, now when I try to access my website I get this error:
ERR_CONNECTION_TIMED_OUT -> on Google Chrome web browser
DNS_PROBE_FINISHED_NXDOMAIN -> on Opera web browser
Any suggestions about what might be wrong?
Thank you once again!
Found it! Google Cloud Platform changed my External IP Address. All I had to do was to reconnect my domain name and I also made sure to have the external IP as static.
Hello again Tony,
I can’t seem to figure out why I do not receive emails sent through contact form.
Do you know what is blocking it?
Hey Tony,
I Love Your Content on Youtube & This Article Is Really Very Helpful For Me But I Faced Some Issues Can You Please Tell Me How To Increase Upload Size in This Nginx WordPress Site.? Because in this site Default size is 2M which is very low.
one more question sorry for disturbing you but it’s really helpful for me.
can you please tell me if any update available on the server level the how I can update that like if PHP version and Nginx version so how I can taggle with this
Check out this post. Just change the apache2 references to nginx and make sure you’re referencing the correct version of PHP
Thanks for the tutorial this is great. I have a few questions about keeping the apps data safe.
So if I stop this instance and restart it will it still have the mysql data and the application installed?
How would you suggest storing a backup of the database?
Hi Jeff. Yes, if you restart the instance, your data will persist. As for MySQL backups, if you use WordPress you can use a plugin, or do something manual like with rsync https://youtu.be/z35ZPELo5_Y
Hello Tony,
Thank you for your tutorial. I am giving it a try.
What if I have two domains and two websites to host. Shall I create a separate VM for each or can I nest both on the same machine?
You can host multiple sites on the same server
Tony ,
May God bless you more,
Your are very helpful
Thanks for the guide. I open my vm IP, it shows “Welcome to nginx!”. Please help.