1. Blogging

How to host your website on Google cloud for free forever

Let’s face it, not everyone can afford to pay for the hosting of their websites, either monthly or yearly. Especially if you are beginner blogging enthusiast on a budget.
The big and reliable hosting providers out there charge exorbitant prices on their customers which makes beginner bloggers shy away from their dreams due to financial constraints.
If you are in this situation, or just want to save a great deal of money from hosting, then you are in the right place.
Some of the big tech providers such as Google have put the considerations of their average consumers in mind. Imagine having to host your website for as little as $0 for an entire year! Yeah, I know it sounds too good to be true. But trust me, I am actually speaking from experience of hosting websites for multiple clients at such a price.
I was also a bit skeptical when I first started out, but it turned out to be true. Besides, all those websites have never been down due to any server issues, which means that the google servers are reliable. Follow the following steps to get your website running on no time:

Step 1: Getting a domain name

The only cost which you will incur is the one of acquiring a domain name, which can be as cheap as $8.99 for a .com domain name and as little as $0.99 for a .site, .online etc domain names on domain providers such as hostinger. The good part is that you will never have to incur this cost again for an entire year!
So, go ahead and grab yourself a domain name from hostinger for the little price and keep your domain management page open. We will need it later.

Step 2: Creating your server

Let us set up our server on the google cloud console. Sign in using your gmail account. If you are first time user of the platform, go ahead and claim your free $300 credit. Google will then ask you for your credit card information. Don’t be scared, they will not auto-charge you anything. They will only perform a $1 transaction to verify the validity of your credit card, and it will be refunded back.
Go through the whole set-up process, which is straight forward, until you end up on your home console as shown below:

Google cloud console

Navigate to your navigation menu on the left, hover over compute engine and select vm instances.

Google cloud console

On the navigation menu at the top, click on create instance. Give your instance any name, preferably, the name of your website. Choose your region, in this example, I will choose US central1 (lowa).
Next is the machine instance. Your choice here will determine if you will be charged and how much will be you will be charged. I assume that we are all creating a static website, and we are all just beginners, meaning the website is not too large and the traffic load is also minimal.
Go ahead and choose f1-micro, which gives you 614MB of memory, which is pretty standard for a static wordpress site and we can definitely maximize on it to get all the benefits of our server instance.
Now in the boot disk section, click on change. The operating system which we will use is ubuntu, and the version will be 18.04 LTS. I will give the boot disk a size of 20GB and click on select.

Google cloud console

For the firewall configuration, allow HTTP and HTTPS traffic.
Now if you check your total bill on the right, you will see a total $4.68 mothly estimate, if you have chosen the same settings as mine.

Google cloud console

Don’t let that figure scare you. That amount will only be charged if you completely use up your chosen resources within a month, which is a bit difficult for a website that is only starting with very little traffic.
If your website grows beyond the chosen resources, you can always come back to your instance and upgrade. (Of course you will now be making some extra bucks and the extra cost will be nothing).
Click on create and wait for a few seconds for your instance to finish creating. Now under you VM instances, you should have your server instance started

Step 3: Configuring Your Server

For the next steps, do not worry if you are not “techy”. I will keep everything simple and super easy to follow along.
If you look at your instance you will notice that it has been assigned an external IP which is ephemeral. Which means, when you switch off your server instance, that IP will change, which will make your website unreachable. Let us change that:
On the 3 vertical ellipsis within your instance, on the far right, click on them and select view network details.

Google cloud console

On the navigation menu on the left, select external ip addresses. Under the type, change the type from ephemeral to static. Give it any name and save.
Now go back to your VM instances and click on SSH. This will open another browser window with a command terminal. Now let us install our web server, which will serve our website files to the internet. In this example we will be using Apache web server.
Copy paste the following commands in the given order on the terminal to begin:

  1. Installing swap
  • sudo su
  • apt update && apt upgrade -y
  • fallocate -l 1G /swapfile
  • dd if=/dev/zero of=/swapfile bs=1024 count=1048576
  • chmod 600 /swapfile
  • mkswap /swapfile
  • swapon /swapfile
  • nano /etc/fstab

The last command above will open a file. Scroll to the bottom of it and using your up/down arrows and add the following line: /swapfile swap swap defaults 0 0 . Press ctrl + o  then enter/return key on your keyboard to save the file and ctrl + x to close the file.
2. Installing LAMP stack (Linux, Apache, MySQL and PHP)

  • apt install tasksel
  • tasksel install lamp-server
  • apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

Step 4: Configuring your domain name

The following process should be neutral to all domain name providers. In this example, I will use hostinger as the domain provider. We need to add an A record which points to the static IP address assigned to our instance by Google. If you are using a different domain provider, review their documentation on how to go about this process.
For hostinger, login to your control panel and click manage on your domain. Navigate to the DNS ZONE tab. At the A (host), click add new.
The host is @ and points to is the external IP found in your google console instance. Leave the TTL to the default value.

Google cloud console

After doing that, you need to be patient for at least an hour to allow the domain to point to that IP address.
Navigate back to your terminal window and type the following commands:

  • cd /etc/apache2/sites-available
  • mv 000-default.conf your_domain_name.conf

NOTE: In the last command above, replace your_domain_name with your actual domain name.

  • nano your_domain_name.conf

The above command should open a file. Before the line:

Add the following code:

<Directory
/var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All Require all granted


Inside the tags that begin with
configure the first 4 un-commented lines to be as follows:
ServerName your_domain_name
ServerAlias www.your_domain_name
ServerAdmin [email protected]
DocumentRoot /var/www/html

Press ctrl + o followed by enter/return to save the file, then ctr + x to close the file.
Now type the following commands to enable your site:

  • mkdir -p /var/www/your_domain
  • a2dissite 000-default.conf
  • a2ensite your_domain.conf
  • systemctl reload apache2

If you now go to your domain name, on the browser, you should see the default Apache welcome page, which means you have successfully pointed your domain to the IP address.
Now let us install a wordpress website:

Step 5: Installing your website

Let us now create a database for our wordpress installation:

  • mysql -u root
  • CREATE DATABASE wordpress;
  • GRANT ALL ON wordpress.* TO 'wordpressuser' IDENTIFIED BY 'password02';
  • quit

NOTE: My database name is wordpress. You can change yours to another name. You can also change wordpressuser to your custom username and password02 to your own password.
Then run the command:
mysql_secure_installation to install mySQL database.
In some cases, you may need to upload large files on your server and the current server configuration may not allow you to do so. To fix that, type the following command:
nano /etc/php/7.2/apache2/php.ini
The above command will open a file. Search for the line saying upload_max_filesize by pressing ctrl + w and typing the search keywords then press enter/return. Change the value from 2M to a higher value, say 50M.
Also search for the line post_max_size and change the value to a higher one, say 21M.

Step 6: Installing wordpress

This is now the final step and you should have an amazing website hosted by yourself at absolutely no cost.
Paste the following commands on your terminal:

  • cd /var/www/html
  • rm -rf index.html
  • wget https://wordpress.org/latest.tar.gz
  • tar -xzvf latest.tar.gz
  • cd wordpress
  • mv * ..
  • cd ..
  • rm -rf wordpress
  • mv wp-config-sample.php wp-config.php
  • nano wp-config.php

The final command above will open a file.  Navigate using your up/down arrows to the following lines:
( 'DB_NAME', 'cyberg' );/** MySQL database name */
define( 'DB_USER', 'root' );/** MySQL database username */
define( 'DB_PASSWORD', 'password02' );/** MySQL database password */
Fill in the details according to the configurations made while installing mySQL. Press ctr + o, then enter/return to save then ctrl + x to exit.
Finally let us change the user permissions for our wordpress installation to avoid errors while installing plugins or themes:
chown -R www-data:www-data /var/www/html/*
If you now navigate to your domain name, you should be able to go ahead with the wordpress installation and customize your site according to your needs.
Feel free to leave a comment if you have any question regarding any step on this awesome way to save money on unnecessary costs on hosting.

No Comments
Comments to: How to host your website on Google cloud for free forever

    Your email address will not be published. Required fields are marked *

    Attach images - Only PNG, JPG, JPEG and GIF are supported.

    Login

    Welcome to Carstly

    Be part of our community by contributing to articles and subscribing to your favorite stories
    Join Carstly
    Registration is closed.

    Pssst! Hey You!

    We are glad you are here! Be part of the Carst loop & get updates on similar posts.

    Subscribe To Our Newsletter

    By signing up, you consent to the privacy policy.