Skip to main content
AT

GitHub Actions CI/CD for Laravel - my production workflow

Alex Thompson Cloud & DevOps 169 views
Sharing my GitHub Actions workflow that I use for deploying Laravel apps. It runs PHPStan, Pint, and PHPUnit before deploying via SSH. The workflow has two jobs: 1. Test job: Checkout code, setup PHP 8.3, composer install, run vendor/bin/pint --test, run vendor/bin/phpstan analyse, run php artisan test. 2. Deploy job (depends on test passing): rsync files to server, run composer install --no-dev, clear and rebuild caches. The key insight: always run Pint in --test mode in CI. It catches formatting issues without modifying files. Also running PHPStan at level 8 catches so many bugs before they reach production. Full workflow file is around 80 lines. Happy to share the complete version if anyone is interested.

2 Replies

EA
Engr Mejba Ahmed 1 week ago
Great workflow Alex! Very similar to what I use for deploying mejba.me and the other sites I manage. A couple of additions I would recommend: 1. Cache Composer dependencies between runs. Saves 30-60 seconds per workflow execution. 2. Use --delete-after with rsync to remove stale files on deploy without causing downtime during the sync. 3. Always run php artisan optimize:clear before rebuilding the cache in production to avoid stale cache issues. One gotcha I learned the hard way: always remove public/hot after deployment if you use Vite. Otherwise production will try to load assets from localhost:5173.
NO
Nina Okafor 1 week ago
Would love to see the full workflow! Also, do you use GitHub environments for staging vs production? I have set up approval gates for production deploys and it has saved us from a few accidents.

Post a Reply