How to Deploy HTML Website to cpanel using FTP from Github (CI/CD)

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

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.
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 "

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.

See more

Kindly share this story:

Leave a Reply

Your email address will not be published.

Required fields are marked*

Comment *

Name*

Email*