Automated FTP Deployment with GitHub Actions
05.04.2024 ยท dayanch
If youโre maintaining a static website or PHP project and youโre still deploying manually via FTP, you can automate it using GitHub Actions.
This article shows how to deploy your code to an FTP server whenever you push to the
main
๐งฉ Required Setup
- Your project should be on GitHub
- You need an FTP server (many shared hostings offer this)
- You must add the following secrets to your repo under :
Settings > Secrets and variables > Actions
FTP_SERVER
FTP_USER
FTP_PASSWORD
๐ Directory Structure
This deploys everything from the root directory (
./
build/
dist/
local-dir
โ
GitHub Workflow: .github/workflows/main.yml
.github/workflows/main.yml
name: Site name on: push: branches: - main jobs: FTP-Deploy-Action: name: FTP-Deploy-Action runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: fetch-depth: 2 - name: Get list of changed files id: changed-files run: | echo "Changed files:" git diff --name-only HEAD^ HEAD echo "::set-output name=files::$(git diff --name-only HEAD^ HEAD | tr '\n' ' ')" echo "files=$changed_files" >> $GITHUB_ENV - name: FTP-Deploy-Action uses: SamKirkland/FTP-Deploy-Action@v4.3.3 with: server: ${{ secrets.FTP_SERVER }} username: ${{ secrets.FTP_USER }} password: ${{ secrets.FTP_PASSWORD }} local-dir: './'
๐ ๏ธ Customization Tips
- Want to upload only certain folders? Use
local-dir: './build'
- Want to deploy only when a tag is pushed? Change to
on.push.branches
on.push.tags
- Need to exclude files like ? Use
.gitignore
optionsexclude
๐ Summary
- Fast, automated, and efficient
- No manual FileZilla needed ever again ๐
- Great for static sites, WordPress themes, and simple PHP apps
You can now deploy directly from GitHub to any shared hosting account with FTP support!