Skip to content
10% off any project with promo code10% off with code

GitHub Actions CI/CD for PHP Projects: A Practical Guide

Contents
  1. Workflow structure
  2. The full workflow
  3. Configuring Secrets
  4. Telegram notification
Published
Reading time
~1 min
Views
119
Reader rating
7 reviews
Author
Yevhen Fostenko
Senior Backend & DevOps Engineer
GitHub Actions CI/CD for PHP Projects: A Practical Guide Article
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

GitHub Actions lets you automate testing and deployment on every push. Here is a ready-made workflow for a PHP project.

Workflow structure

.github/workflows/deploy.yml

The full workflow

name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          extensions: pdo_mysql, redis, gd
      - run: composer install --no-dev
      - run: ./vendor/bin/phpunit

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy via SSH
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            cd /var/www/html
            git pull origin main
            composer install --no-dev --optimize-autoloader
            php artisan cache:clear 2>/dev/null || true

Configuring Secrets

GitHub repo → Settings → Secrets → New secret:
SSH_HOST, SSH_USER, SSH_PRIVATE_KEY

Telegram notification

- name: Telegram Notification
  uses: appleboy/telegram-action@master
  with:
    to: ${{ secrets.TELEGRAM_CHAT_ID }}
    token: ${{ secrets.TELEGRAM_TOKEN }}
    message: "✅ Deploy successful: ${{ github.sha }}"

Need CI/CD set up? Order GitHub Actions configuration.

Tags: github actionsci/cdphpdeploymentautomation
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

Reader reviews

4.0
Write a review