DEV Community

vimuth
vimuth

Posted on • Edited on

Deploy from git to hostinger (Shared hosting).

What is hostinger.

Hostinger is a web hosting company that was established in 2004. It offers a variety of hosting services, including shared hosting, cloud hosting, Virtual Private Server (VPS) hosting, and more recently, WordPress hosting. The company is known for providing affordable and scalable hosting solutions aimed at both beginners and experienced web developers.

In this tutorial we talk about deploying from git to hostinger shared web hosting.

1.First create a git repocitory.

Image description

then clone it to your local machine.

If it is a private repository you can create a PAT or personal access token. And clone like.

git clone https://gitusername:pat_token@github.com/Account/repo.git .
Enter fullscreen mode Exit fullscreen mode

It is better if you can give expire time for personal access token to never expire since it will help if you can create an github action.

2.Create a file folder and subdomain

This tutorial assumes that you have already bought a domain and connected to hosting.

Image description

Go there and create a folder inside public_html called test.

Then create a subdomain from dashboard and connect to this folder.
Got to Domains -> Subdomains

Image description

This will automatically choose test inside public_html.

Image description

Now in browser https://test.yourdomain.com/ you can see the test page.

3.Connect github

  • Go to github get ssh url like this

Image description

  • now got to git section in hostinger dashboard

Image description

  • Now add this ssh url and give your branch. For me it was default main branch. And give "test" as Directory.

These are example urls:
For public repositories: https://github.com/WordPress/WordPress.git
For private repositories: git@github.com:WordPress/WordPress.git

Image description

Now go below and you can see an entry like this.

Image description

When you click the Deploy button the changes will not deployed from to hostinger server. The reason is you need to verify the server with a Deploy key. This is how we get a Deploy key from hostinger and add it to git.

The deploy key has to be taken from here

Image description

now copy it and add to git repo. For this go to the repository and add deploy key like this

Image description

Now you click yellow Deploy button the changes from git will deployed to hostinger server. But there is an automatic deploy option. What this does is every time we commit to the github they will automatically deploy to the hostinger. Github has given two ways for this. Easiest way is GitHub Webhooks.

4.Github Webhooks

A webhook in GitHub is a mechanism that allows you to configure GitHub to send real-time data to an external server whenever certain events occur in a repository. This is useful for automating workflows, integrating with external services, and keeping systems synchronized.

Here's how it works:

Setting Up a Webhook:

1.You configure a webhook in your GitHub repository settings.
2.You specify a payload URL, which is the endpoint on your server where GitHub will send HTTP POST requests.
3.You choose the events that will trigger the webhook (e.g., push events, pull requests, issues).

This is how you do it.

  • Got to repository and enter settings->webhooks

Image description

  • Then we need to get webhook URL from Hostinger.

Image description

After click this you can get the webhook URL. And add it to setting->webhook screen inside "Payload URL".

Now every time we commit to repo a webhook will work and contents will be deployed to server.

Top comments (0)