Deploy from git to hostinger (Shared hosting).
Published: 2024-06-20 16:14:28

##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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uk4kvf93eon6vf0w5rgx.png)

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 .
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob26y3pubdzdh7bejqns.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/57491whtjrwv2q5kmvgc.png)

This will automatically choose **test** inside **public_html**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0t08yhc93othbqkl2qg.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a07ekmcuz6okba0gg4gc.png)

- now got to git section in hostinger dashboard

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ojgzia8j0z3lqh2q78z.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tkopnvo2gh2eolqle5i1.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tab8cxpj1lxo0ngxa2js.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ul58i7ii3zo0y1jnl0ro.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtfl0q6uyldny79027tf.png)


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:

**<u>Setting Up a Webhook:</u>**

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q8okk6bvhic19e6if7ha.png)

- Then we need to get webhook URL from Hostinger.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uqodi39u3vsjq7nrz45i.png)

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.