How to Deploy HTML Website to cpanel using FTP from Github (CI/CD)
July 23, 2024
Automate deployment to cpanel from Github using FTP and Github actions
Latest in tech
Software Dev
Introduction
Uploading files to cPanel manually is boring and stressful in 2024. In this article, I'll show you how to automate your deployment to cPanel so you no longer need to manually deploy your files.
Why use FTP
FTP stands for File Transfer Protocol, and it makes it very easy to transfer files in cPanel. The combination of FTP and GitHub Actions creates a CI/CD flow for automating file transfers across both servers, taking the stress away from you.
Steps
- Create an FTP account : On cPanel, search for "FTP" and click on it. You’ll be taken to a page displaying all existing FTP accounts. Click on the Create Account button and input a username, password, quota (depending on the size of your files), and directory (e.g., /home2/username/public_html). Click the Create button to create your FTP account.
Note: In my case, the /home2/username was already specified and I just had to add public_html. Click the "Create" button to create your FTP account.
- Create Github secrets : Go to your GitHub repository, click on Settings > Secrets and variables > Actions > New repository secret. You'll need to create these three secrets:
- Name: FTP_PASSWORD
Value: your-ftp-password - Name: FTP_USERNAME
Value: your-ftp-username - Name: FTP_SERVER
Value: your-ftp-server
- Name: FTP_PASSWORD
- Create Github Workflow : In your project folder, create a directory at the root named .github/workflows. Inside this directory, create a file named main.yaml. Then, paste the following code into main.yaml:
name: Publish website to cPanel
on:
push:
branches:
- main
jobs:
FTP-Deploy-Action:
name: FTP Deploy Action
runs-on: ubuntu-latest
steps: - name: Checkout code
uses: actions/checkout@v2.1.0
with:
fetch-depth: 2
- name: Install lftp
run: sudo apt-get install -y lftp
- name: Deploy to FTP server
env:
FTP_SERVER: ${{ secrets.FTP_SERVER }}
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
LOCAL_DIR: "./"
REMOTE_DIR: "/public_html"
run: |
lftp -f "
set ssl:verify-certificate no
open $FTP_SERVER
user $FTP_USERNAME $FTP_PASSWORD
lcd $LOCAL_DIR
cd $REMOTE_DIR
mirror --reverse --delete --verbose --exclude .ftpquota
bye "
- Push to Github: Push the new changes to GitHub, and then navigate to the Actions tab in your repository to see the deployment process.
Conclusion
Deploying manually can be difficult, and you don’t deserve to go through that amount of stress just to keep a webpage running. Hopefully, this article helps you streamline the process. Feel free to leave a comment if you have any questions or encounter any issues.
Leave a Reply
Your email address will not be published.
Required fields are marked*
Comment *
Name*
Email*