Ferhat Gölge
Bilgisayar Amelesi
VPS Üzerinde Laravel AI Projesi Yayına Alma
(Apache VirtualHost + SSL + GitHub SSH Kurulumu)
Bu rehberde, ai.kitmote.com gibi bir subdomain’i sıfırdan yayına alacağız.
Kuracağımız yapı:
- Apache VirtualHost
- SSL (Let’s Encrypt)
- GitHub SSH deploy
- Laravel klasör yapısı uyumlu çalışma
1️⃣ Apache VirtualHost Kurulumu
📁 Proje dizini
Önce projenin doğru yerde olduğundan emin ol:
mkdir -p ai.kitmote.com
cd ai.kitmote.com
Laravel projesi burada olacak.
📄 VirtualHost dosyası oluştur
İçine şunu yaz:
<VirtualHost *:80>ServerName ai.kitmote.comServerAlias www.ai.kitmote.comDocumentRoot /var/www/ai.kitmote.com/public<Directory /var/www/ai.kitmote.com/public>AllowOverride AllRequire all granted</Directory>ErrorLog ${APACHE_LOG_DIR}/ai_error.logCustomLog ${APACHE_LOG_DIR}/ai_access.log combined</VirtualHost>🔧 Apache modüllerini aç
🔗 Siteyi aktif et
Varsa default kapat:
🔄 Apache restart
✅ Test
Tarayıcıdan:
Laravel varsa açılmalı.
2️⃣ SSL Kurulumu (Let’s Encrypt)
📦 Certbot kur
sudo apt install certbot python3-certbot-apache -y
🔐 SSL al
Sorular:
- Email → gir
- Redirect HTTP → YES seç (önemli)
🔁 Auto-renew kontrol
✅ Test
3️⃣ GitHub SSH Key Kurulumu
Production deploy için en sağlıklı yöntem: SSH
🔑 SSH key oluştur
Enter → Enter → Enter
🔍 Public key al
Çıkan şeyi kopyala.
🔗 GitHub’a ekle
GitHub →
👉 Settings → SSH and GPG Keys → New SSH Key
🔌 Test
Çıktı:
4️⃣ Projeyi Sunucuya Çekme
name: Deploy AI Kitmoteon:push:branches:- masterconcurrency:group: deploy-ai-kitmote-${{ github.ref }}cancel-in-progress: truejobs:deploy:runs-on: ubuntu-lateststeps:- name: Checkoutuses: actions/checkout@v4- name: Setup PHPuses: shivammathur/setup-php@v2with:php-version: '8.4'extensions: mbstring, xml, ctype, iconv, intl, pdo_mysql, bcmath, zip, curltools: composer- name: Install Composer dependenciesrun: composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress- name: Setup Nodeuses: actions/setup-node@v4with:node-version: '20'cache: npm- name: Install Node dependenciesrun: npm ci- name: Build assetsrun: npm run build- name: Start SSH agent (deploy key)uses: webfactory/ssh-agent@v0.9.0with:ssh-private-key: ${{ secrets.VPS_SSH_KEY }}- name: Trust VPS host keyenv:VPS_HOST: ${{ secrets.VPS_HOST }}run: |mkdir -p ~/.sshchmod 700 ~/.sshssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hostschmod 644 ~/.ssh/known_hosts- name: Rsync project to VPSenv:VPS_USER: ${{ secrets.VPS_USER }}VPS_HOST: ${{ secrets.VPS_HOST }}run: |export RSYNC_RSH="ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts"rsync -avz --delete \--exclude=".git" \--exclude=".github" \--exclude=".env" \--exclude=".env.*" \--exclude="node_modules" \--exclude="storage/logs" \--filter="protect .env" \--filter="protect .env.*" \./ "${VPS_USER}@${VPS_HOST}:/var/www/ai.kitmote.com/"- name: Run deploy commands on VPSenv:VPS_USER: ${{ secrets.VPS_USER }}VPS_HOST: ${{ secrets.VPS_HOST }}run: |ssh -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$HOME/.ssh/known_hosts" \"${VPS_USER}@${VPS_HOST}" bash -s << 'REMOTE'set -euo pipefailcd /var/www/ai.kitmote.com# storage/framework Git’te yoksa rsync taşımaz; artisan down / view:clear patlarmkdir -p storage/framework/cache/datamkdir -p storage/framework/sessionsmkdir -p storage/framework/testingmkdir -p storage/framework/viewsmkdir -p storage/logsmkdir -p bootstrap/cacheexport COMPOSER_ALLOW_SUPERUSER=1php artisan down || truecomposer install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progressphp artisan migrate --forcephp artisan optimize:clearphp artisan config:cachephp artisan route:cachephp artisan view:cachephp artisan storage:link || truephp artisan queue:restart || truechown -R www-data:www-data storage bootstrap/cachechmod -R 775 storage bootstrap/cachephp artisan upREMOTE
VPS_HOST = ip adresi
VPS_USER = kullanıcı
VPS_SSH_KEY = cat ~/.ssh/id_ed25519 gelen bütün değer.
Public anahtarı authorized_keys’e ekle
örnek :
sudo -u kitmotedeploy ssh-keygen -t ed25519 -C “gh-actions@kitmotedeploy” -f /home/kitmote/.ssh/gh_actions -N “”
sudo chown kitmotedeploy:kitmote /home/kitmote/.ssh/authorized_keys
sudo chmod 600 /home/kitmote/.ssh/authorized_keys
sudo chmod 700 /home/kitmote/.ssh
⚠️ İzinleri düzelt
sudo chmod -R 755 /var/www/ai.kitmote.com
Laravel özel:
5️⃣ Laravel Kurulum Adımları
📦 Bağımlılıklar
⚙️ ENV
nano .env
🔑 Key üret
🗄️ Migration
⚡ Cache optimize
php artisan route:cache
php artisan view:cache
6️⃣ Production Tavsiyeleri
🔥 Queue (opsiyonel)
Supervisor ile önerilir.
🔍 Log kontrol
🔄 Deploy sonrası update
composer install --no-dev
php artisan migrate --force
php artisan optimize
7️⃣ Sık Karşılaşılan Hatalar
❌ 403 Forbidden
→ AllowOverride açık mı?
→ Apache rewrite aktif mi?
❌ 500 Error
→ .env hatası
→ storage izinleri
❌ 502 / boş sayfa
→ Apache çalışıyor mu?
🎯 Sonuç
Bu yapı ile:
- ✅ Domain → VPS bağlandı
- ✅ Apache → Laravel çalışıyor
- ✅ SSL → aktif
- ✅ GitHub → otomatik deploy hazır
Keywords: VPS, SSH_KEY, github CI/CD