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.
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.
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
This will automatically choose test inside public_html.
Now in browser https://test.yourdomain.com/ you can see the test page.
3.Connect github
- Go to github get ssh url like this
- now got to git section in hostinger dashboard
- 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
Now go below and you can see an entry like this.
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
now copy it and add to git repo. For this go to the repository and add deploy key like this
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
- Then we need to get webhook URL from Hostinger.
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)