Laravel: Sıfırdan İleri Seviye

Ders 17/17 1 saat 5 dk

Deployment ve Production

Production hazırlığı, deployment stratejileri, optimizasyon ve monitoring.

Deployment ve Production

Laravel uygulamanızı production ortamına hazırlayın ve deploy edin.

Production Checklist

# .env (Production)
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com

LOG_CHANNEL=daily
LOG_LEVEL=error

CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

Optimizasyon Komutları

# Tüm optimizasyonları çalıştır
php artisan optimize

# Veya ayrı ayrı
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

# Autoloader optimizasyonu
composer install --optimize-autoloader --no-dev

Deployment Script

#!/bin/bash
# deploy.sh

cd /var/www/html

# Maintenance mode
php artisan down

# Git pull
git pull origin main

# Composer install
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev

# NPM build
npm ci
npm run build

# Migration
php artisan migrate --force

# Optimize
php artisan optimize

# Restart queue workers
php artisan queue:restart

# Clear and warm cache
php artisan cache:clear

# Maintenance mode off
php artisan up

Nginx Konfigürasyonu

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /var/www/html/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Laravel Forge / Vapor

  • Laravel Forge: Sunucu yönetimi, SSL, deployment otomasyonu
  • Laravel Vapor: Serverless deployment (AWS Lambda)
  • Envoyer: Zero-downtime deployment

Monitoring

  • Laravel Telescope: Debug ve monitoring (development)
  • Laravel Pulse: Real-time application performance
  • Sentry: Error tracking
  • New Relic / Datadog: APM

Önemli Noktalar

  • config:cache, route:cache, view:cache ile optimizasyon
  • APP_DEBUG=false production'da
  • Queue worker'lar için Supervisor
  • SSL/HTTPS zorunlu
  • Laravel Forge veya Vapor ile kolay deployment