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.