You do not need to purchase a hosting service just to host your static website. You can host your static site for free on Github pages in five simple steps.
Github provide free hosting service for static sites and it is very easy to connect the domain to Github pages. You just need to follow the 5 steps explained below and that’s it. Your site will be live within 5-10 minutes.
Steps to publish your static website on Github pages
Step 1: Purchase a domain
There are lots of domain providers such as Godaddy from where you can purchase an unique domain.
Step 2: Create an account on Github
Go to the Github and create your account with the required information.
You can choose your repository name as per your wish.
Make sure you tick the Public option else your site won’t be published.
Also, tick the checkbox button to automatically create the README file for your repository.
Step 3: Create a file with name “CNAME”
- 1. Click on the “Create new file” and create a file with name “CNAME”.
- 2. In the editor area, write your domain name in the first line.
- 3. Commit the change.
Step 4: Upload Your Static Website
Now, it’s time to upload your static site. Click on “Upload files” and upload your site source code or you can create a new file and add the code in editor area and save/commit it.
If you have the folders inside the folders then you will have to create the directory/folder and then you can upload the file in that folder.
To create a folder name, you just have to write folder name and put “/” after that. Then you can write any dummy file name like Test.txt.
Note that Github does not support empty folder. So, when you create a folder, create any dummy text file (for eg. Test.txt). See below image:
Once your static site is fully uploaded, go to your domain DNS setting and make changes as explained in step 5.
Step 5: Change the DNS records
Now, you will need to point your domain to the Github. Github has four IPs which we will need to add in our DNS records. For example, in Godaddy, you can go to DNS setting, and update the record as below:
Below are the Github IPs that you will need to add in the records.
- 1. 185.199.108.153
- 2. 185.199.109.153
- 3. 185.199.110.153
- 4. 185.199.111.153
Bingo! Your domain is now connected with your Github repository. It will take few minutes to connect so you can check it after 5 or 10 minutes.
Above were the steps that I followed to host one of my website on Github pages.
If you like this article or if you have any questions or need any help, feel free to email me.
You can also contact me if you need any help with static or dynamic website development.
Cheers!!