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:

cd /var/www
mkdir -p ai.kitmote.com
cd ai.kitmote.com
 

Laravel projesi burada olacak.


📄 VirtualHost dosyası oluştur

 
sudo nano /etc/apache2/sites-available/ai.kitmote.com.conf
 

İçine şunu yaz:

 
<VirtualHost *:80>
ServerName ai.kitmote.com
ServerAlias www.ai.kitmote.com

DocumentRoot /var/www/ai.kitmote.com/public

<Directory /var/www/ai.kitmote.com/public>
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/ai_error.log
CustomLog ${APACHE_LOG_DIR}/ai_access.log combined
</VirtualHost>
 

🔧 Apache modüllerini aç

 
sudo a2enmod rewrite
 

🔗 Siteyi aktif et

 
sudo a2ensite ai.kitmote.com.conf
 

Varsa default kapat:

 
sudo a2dissite 000-default.conf
 

🔄 Apache restart

 
sudo systemctl restart apache2
 

✅ Test

Tarayıcıdan:

 
http://ai.kitmote.com
 

Laravel varsa açılmalı.


2️⃣ SSL Kurulumu (Let’s Encrypt)

📦 Certbot kur

 
sudo apt update
sudo apt install certbot python3-certbot-apache -y
 

🔐 SSL al

 
sudo certbot --apache -d ai.kitmote.com 
 

Sorular:

  • Email → gir
  • Redirect HTTP → YES seç (önemli)

🔁 Auto-renew kontrol

 
sudo certbot renew --dry-run
 

✅ Test

 
https://ai.kitmote.com
 

3️⃣ GitHub SSH Key Kurulumu

Production deploy için en sağlıklı yöntem: SSH


🔑 SSH key oluştur

 
ssh-keygen -t ed25519 -C "server@kitmote"
 

Enter → Enter → Enter


🔍 Public key al

 
cat ~/.ssh/id_ed25519
 
Bu kısımdaki bütün değeri al.
 

Çıkan şeyi kopyala.


🔗 GitHub’a ekle

GitHub →
👉 Settings → SSH and GPG Keys → New SSH Key


🔌 Test

 
ssh -T git@github.com
 

Çıktı:

 
Hi username! You've successfully authenticated
 

4️⃣ Projeyi Sunucuya Çekme

Örnek Bir .github/workflows/deploy.yml 
 
name: Deploy AI Kitmote

on:
push:
branches:
- master

concurrency:
group: deploy-ai-kitmote-${{ github.ref }}
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, xml, ctype, iconv, intl, pdo_mysql, bcmath, zip, curl
tools: composer

- name: Install Composer dependencies
run: composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm

- name: Install Node dependencies
run: npm ci

- name: Build assets
run: npm run build

- name: Start SSH agent (deploy key)
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.VPS_SSH_KEY }}

- name: Trust VPS host key
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
run: |
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan -H "$VPS_HOST" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts

- name: Rsync project to VPS
env:
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 VPS
env:
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 pipefail
cd /var/www/ai.kitmote.com

# storage/framework Git’te yoksa rsync taşımaz; artisan down / view:clear patlar
mkdir -p storage/framework/cache/data
mkdir -p storage/framework/sessions
mkdir -p storage/framework/testing
mkdir -p storage/framework/views
mkdir -p storage/logs
mkdir -p bootstrap/cache

export COMPOSER_ALLOW_SUPERUSER=1

php artisan down || true

composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress

php artisan migrate --force
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan storage:link || true
php artisan queue:restart || true

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

php artisan up
REMOTE
VPS_HOST = ip adresi

VPS_USER = kullanıcı

VPS_SSH_KEY = cat ~/.ssh/id_ed25519 gelen bütün değer.
bu değerleri github kısmında repository settings -> Secret And Variables -> Action alanında New respository secret butonuna basarak gir.
 
 
sonrasında git ile projeni gönderdiğinde github sunucuya otomatik bağlanır ve kurulumu gerçekleştirir. 
 
git commit -m "deploy"
git push 
 
bu kısımda izinlerde hata alınabilir. 
 

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

Yetkilerde hata verebilir. deploy yapan kullanıcı için yetkileri düzenle.
 
sudo chown -R www-data:www-data /var/www/ai.kitmote.com
sudo chmod -R 755 /var/www/ai.kitmote.com
 

Laravel özel:

 
chmod -R 775 storage bootstrap/cache
 

5️⃣ Laravel Kurulum Adımları

📦 Bağımlılıklar

 
composer install --no-dev --optimize-autoloader
 

⚙️ ENV

 
cp .env.example .env
nano .env
 

🔑 Key üret

 
php artisan key:generate
 

🗄️ Migration

 
php artisan migrate
 

⚡ Cache optimize

 
php artisan config:cache
php artisan route:cache
php artisan view:cache
 

6️⃣ Production Tavsiyeleri

🔥 Queue (opsiyonel)

 
php artisan queue:work
 

Supervisor ile önerilir.


🔍 Log kontrol

 
tail -f storage/logs/laravel.log
 

🔄 Deploy sonrası update

 
git pull origin main
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?

 
sudo systemctl status apache2
 

🎯 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

Yorumlar

Log in or sign up to write a comment
Giriş
Sign Up