In today's fast-paced web development landscape, efficient version control and deployment practices are crucial. Integrating GitHub with cPanel provides a powerful solution for managing and deploying your web applications seamlessly. In this article, we'll guide you through the process of setting up a GitHub account and linking it to cPanel.
A- Setting Up a GitHub Account
1. Create a GitHub Account:
Visit GitHub and sign up for a new account if you don't have one.
2. Create a New Repository:
1- Click on the "+" sign in the top right corner and select "New repository."
2- Provide a name, description, visibility, and initialize with a README.
3- Click "Create repository."
B- Linking GitHub to cPanel
1. Install Git on Your Server:
Ensure Git is installed on your server using the package manager.
2. Generate SSH Key:
- Run ssh-keygen on your server to generate an SSH key.
- Copy the key to your clipboard using cat ~/.ssh/id_rsa.pub.
3. Add SSH Key to GitHub:
Add the SSH key to GitHub SSH settings.
4. Clone Repository to Server:
On your server, clone the repository using the SSH URL:
" git clone [email protected]:username/repository.git "
C- Configure Webhooks in GitHub
In your GitHub repository, go to "Settings" -> "Webhooks" -> "Add webhook."
1. Enter the Payload URL (use your cPanel domain) and set the Content type to application/json.
2. Add a secret if needed and select events to trigger the webhook.
3. Click "Add webhook."
Set Up Deployment Script:
Create a deployment script (e.g., deploy.sh) in your repository.
Example script:
#!/bin/bash
git pull origin main
Configure cPanel Cron Job
In cPanel, go to "Cron Jobs" and add a new cron job.
Schedule the job to run your deployment script at your desired interval.
Conclusion
By linking GitHub to cPanel, you establish a streamlined workflow for version control and automated deployment. Changes pushed to your GitHub repository trigger automatic updates on your cPanel server, ensuring your web application is always up-to-date. This integration enhances collaboration and accelerates the development process. Implement these steps today to experience the efficiency and convenience of a synchronized development environment.