deployment Junior

How to deploy Laravel?

Short Answer

Deploy via Git pull, composer install, migrations, config caching, and queue worker restart. Use Supervisor for processes, Nginx for web server.

Detailed Answer

Laravel deployment steps: 1. Server setup: Ubuntu + Nginx + PHP-FPM + MySQL/Redis 2. Code deployment: Git pull, composer install --no-dev 3. Environment: Configure .env with production values 4. Database: Run migrations with --force 5. Caching: config:cache, route:cache, view:cache 6. Permissions: Set storage and bootstrap/cache permissions 7. Queue workers: Start with Supervisor 8. Scheduler: Cron job running schedule:run 9. SSL: Configure HTTPS with Let's Encrypt 10. Monitoring: Set up logging and error tracking Deployment tools: Laravel Forge, Envoyer, GitHub Actions, Deployer.

Code Example

Example
# Deployment script
#!/bin/bash
set -e

cd /var/www/laravelhub

git pull origin main
composer install --no-dev --optimize-autoloader

php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache

php artisan storage:link
php artisan queue:restart

chown -R www-data:www-data storage bootstrap/cache
chmod -R 775 storage bootstrap/cache

# Supervisor config
[program:laravel-worker]
command=php artisan queue:work --sleep=3 --tries=3
user=www-data
autostart=true
autorestart=true
numprocs=2

# Cron
* * * * * cd /var/www/laravelhub && php artisan schedule:run

Interview Tip

Mention deployment tools (Forge, Envoyer) and CI/CD pipelines. Emphasize --force on migrations and the importance of Supervisor for queue workers.