Managing a website can become tedious, especially when you frequently update files like your CV or other resources. A streamlined workflow using GitHub and cPanel allows you to automate the deployment process and ensure that your website always reflects the latest changes. In this article, I’ll walk you through how I automated updates to my subdomain (https://cv.fahimmuntashir.com/
) using GitHub and cPanel.
Step 1: Setting Up Your GitHub Repository
The first step is to host your website’s code on GitHub.
- Create a GitHub Repository
- Log in to GitHub and create a new repository (e.g.,
cv-subdomain
). Clone the repository to your local machine:
git clone https://github.com/your-username/cv-subdomain.git cd cv-subdomain
- Log in to GitHub and create a new repository (e.g.,
- Organize Your Repository
- Ensure that all your files (e.g.,
index.html
, your CV PDF) are in the root directory of the repository. Avoid nesting them inside folders likepublic_html
. Your repository structure should look like this:
cv-subdomain/ ├── index.html ├── Fahim_Muntashir_v2.pdf
- Ensure that all your files (e.g.,
- Push Files to GitHub
Add and commit your files:
git add . git commit -m "Initial commit" git push origin main
Step 2: Setting Up cPanel for Deployment
cPanel doesn’t directly integrate with GitHub, but you can use FTP to deploy your files automatically.
1. Create an FTP Account in cPanel
- Log in to cPanel and navigate to FTP Accounts.
- Create a new FTP account with the following details:
- Directory:
/public_html/cv
- Username: Something like
cv_user
. - Password: Set a strong password.
- Directory:
2. Configure GitHub Secrets
To securely store your FTP credentials, use GitHub Secrets:
- Go to your GitHub repository, navigate to Settings > Secrets and variables > Actions, and add the following secrets:
FTP_SERVER
: Your FTP server (e.g.,ftp.yourdomain.com
).FTP_USERNAME
: The username of the FTP account you created (e.g.,cv_user
).FTP_PASSWORD
: The password for your FTP account.
Step 3: Automate Deployment with GitHub Actions
GitHub Actions lets you automate the process of deploying your website to cPanel whenever you push changes to the repository.
- Create a Workflow File
- In your repository, create a folder named
.github/workflows
. Add a file named
deploy.yml
with the following content:name: Deploy to cPanel via FTP on: push: branches: - main jobs: ftp-deploy: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v3 - name: Deploy to FTP Server uses: SamKirkland/FTP-Deploy-Action@v4.3.0 with: server: ${{ secrets.FTP_SERVER }} username: ${{ secrets.FTP_USERNAME }} password: ${{ secrets.FTP_PASSWORD }} local-dir: ./ server-dir: /public_html/cv/
- In your repository, create a folder named
- Push Your Workflow File
Commit and push the workflow file to your repository:
git add .github/workflows/deploy.yml git commit -m "Add GitHub Actions workflow for FTP deployment" git push origin main
- Verify the Workflow
- Go to the Actions tab in your GitHub repository to ensure the workflow runs successfully.
- Once the workflow completes, your files should be uploaded to
/public_html/cv
on your server.
Step 4: Test and Update
Now that the deployment is automated:
- Test Your Subdomain: Visit your subdomain (e.g.,
https://cv.fahimmuntashir.com/
) to ensure the changes are reflected. Update Files Easily: To update your CV or other files, simply replace them in your repository and push the changes:
git add . git commit -m "Update CV" git push origin main
The workflow will automatically deploy the updated files to your server.
By integrating GitHub with cPanel through GitHub Actions and FTP, you can simplify your website deployment process. This setup ensures that every update you push to GitHub is automatically reflected on your website, saving you time and effort. If you haven’t already, consider adopting this workflow to manage your website more efficiently.
Thanks for reading. I hope you have learn something from this article. If you think this article can help your friends please do share with your friends.
Leave a comment
Your email address will not be published. Required fields are marked *