Articles on: Web Hosting

How to Automatically Deploy from GitHub to cPanel

Elevate your web development game by automating GitHub to cPanel deployments. With Sam Kirkland's FTP Deploy GitHub Action, you can have a smooth transition from coding to production, allowing you to focus on your code, not deployment hassles.

Please note that this method will require you to have a FTP Account to the public_html or subdomain folder already made for the Automatic Deployment. You can follow our FTP Account on cPanel Article on how you can create one.

How to Automatically Deploy from GitHub to cPanel



On your GitHub Repository, go to the Repository's Settings and then go to the Actions' Secrets and Variables



Create 3 New Repository Secrets:
Secret NameSecret Value
FTP_SERVERSet this to the domain to your website, for this article we will be setting it up for the sparkedhost.rob0520.xyz domain
FTP_USERNAMESet this to the Username of the FTP Account
FTP_PASSWORDSet this to the Password of the FTP Account






Go to the Repository's Actions and click on the set up a workflow yourself hyperlink. If you have previously made a different GitHub Action, click on the "New Workflow" button and you should be able to see the hyperlink.



Copy the following code and paste it to the Action file contents, then Commit Changes.

on: push
name: 🚀 Deploy website on push
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v3
    
    - name: 📂 Sync files
      uses: SamKirkland/FTP-Deploy-Action@v4.3.4
      with:
        server: ${{ secrets.FTP_SERVER }}
        username: ${{ secrets.FTP_USERNAME }}
        password: ${{ secrets.FTP_PASSWORD }}


Optionally, if you want to exclude certain folders or files from the Automatic Deployment, let's say a folder named logs and a file named notes.txt for example. You can paste the following lines at the end of the Action:

exclude: |
    **/.git*
    **/.git*/**
    **/logs/**
    notes.txt


If you do require to exclude certain folders or files, make sure to also list down **/.git* and **/.git*/** like the above, as having the exclude key overwrites the default values.

So it will look something like this:

on: push
name: 🚀 Deploy website on push
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v3
    
    - name: 📂 Sync files
      uses: SamKirkland/FTP-Deploy-Action@v4.3.4
      with:
        server: ${{ secrets.FTP_SERVER }}
        username: ${{ secrets.FTP_USERNAME }}
        password: ${{ secrets.FTP_PASSWORD }}
        exclude: |
            **/.git*
            **/.git*/**
            **/logs/**
            notes.txt


Now, every time you commit changes on the Repository. It will automatically deploy the changes to your website!


If you require any further assistance, please create a ticket here.


Created By: Alecz R.

Updated on: 22/12/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!