Steps to Set Up CI/CD from GitHub to Hostinger:
by iamvkr on
Hostinger FTP/SFTP Credentials
First, make sure you have your Hostinger FTP/SFTP credentials
(If not, you can create one). You can find these in the Hostinger control panel under
Files
> FTP Accounts
.
Host: ftp.yourdomain.com (or the specific FTP host)
Username: (your FTP username)
Password: (your FTP password)
Create a GitHub Action for CI/CD:
GitHub Actions allows you to automate workflows directly from your GitHub repository. You can create a workflow that will trigger on each push to your repository and then deploy the changes to Hostinger.
Set Up the Workflow File:
Inside your GitHub repo, create a .github/workflows
directory if it doesn’t already exist.
Inside this folder, create a file
named deploy.yml
(or something similar).
Here’s a basic template for the GitHub Action using FTP to deploy your HTML:
name: Deploy to Hostinger
on:
push:
branches:
- main # Change this to your branch name if it's not 'main'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install FTP client
run: sudo apt-get install lftp
- name: Deploy to Hostinger via FTP
env:
FTP_SERVER: ${{ secrets.FTP_SERVER }}
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
run: |
lftp -e "mirror -R ./ /public_html; quit" -u $FTP_USERNAME,$FTP_PASSWORD $FTP_SERVER
Add Secrets to GitHub
To keep your FTP credentials secure, you’ll need to add them as secrets in your GitHub repository:
Go to your GitHub repository, and navigate to
Settings
> Secrets and Variables
> Actions
Add the following secrets:
FTP_SERVER
: ftp.yourdomain.com (or whatever your FTP server address is)FTP_USERNAME
: Your FTP usernameFTP_PASSWORD
: Your FTP password
Test the Workflow:
After pushing your changes to the main branch (or whichever branch you configured in the GitHub Actions YAML file), the workflow will automatically run.
It will push your updated files to the /public_html
folder on your Hostinger account (or whatever folder you configure).
Verify the Deployment:
Once the GitHub Action runs successfully, visit your domain, and you should see the updated HTML page reflecting the changes you made on GitHub.
Additional Considerations:
-
Custom Directory: If you’re using a subdirectory or have custom file locations, adjust the mirror
-R
command accordingly. -
Automatic Deployment on Pull Requests: You can set the action to deploy on pull request merges or any other specific event instead of just pushes to the main branch.
-
Advanced Options: If you’re using build tools like npm, you can extend this workflow to run a build process before deploying (e.g., npm run build or gulp).
Final Thought
So automating the CI/CD workflow can definitely make the process of deployment a breeze. Once successfully setup, the workflow automatically pushes the changes to your hostinger webisite, which automaticaly reflect on your website.