Ferhat Gölge
Computer Worker
© 2025 All rights reserved.
Deploying a Laravel AI Project on a VPS
(Apache VirtualHost + SSL + GitHub SSH Setup)
In this guide, we'll launch a subdomain like ai.kitmote.com from scratch.
The structure we will establish:
- Apache VirtualHost
- SSL (Let's Encrypt)
- GitHub SSH deploy
- Laravel folder structure compatible operation.
1️⃣ Apache VirtualHost Installation
📁 Project directory
First, make sure the project is in the right place:
cd /var/www
mkdir -p ai.kitmote.com
cd ai.kitmote.com
mkdir -p ai.kitmote.com
cd ai.kitmote.com
The Laravel project will be here.
📄 Create a VirtualHost file
sudo nano /etc/apache2/sites-available/ai.kitmote.com.conf
Write this inside:
<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>
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>
🔧 Enable Apache modules
sudo a2enmod rewrite
🔗 Activate the site
sudo a2ensite ai.kitmote.com.conf
If it's available, disable it by default:
sudo a2dissite 000 -default .conf
🔄 Apache restart
sudo systemctl restart apache2
✅ Test
From the browser:
http://ai.kitmote.com
It should open if you have Laravel.
2️⃣ SSL Setup (Let's Encrypt)
📦 Certbot setup
sudo apt update
sudo apt install certbot python3-certbot-apache -y
sudo apt install certbot python3-certbot-apache -y
🔐 Get SSL
sudo certbot --apache -d ai.kitmote.com -d www.ai.kitmote.com
Questions:
- Email → Log in
- Redirect HTTP → Select YES (important)
🔁 Auto-renew control
sudo certbot renew --dry-run
✅ Test
https://ai.kitmote.com
3️⃣ GitHub SSH Key Setup
The most reliable method for production deployment is SSH.
🔑 Generate SSH key
ssh-keygen -t ed25519 -C "server@kitmote"
Enter → Enter → Enter
🔍 Get public key
cat ~/.ssh/id_ed25519.pub
Copy what comes up.
🔗 Add to GitHub
GitHub →
👉 Settings → SSH and GPG Keys → New SSH Key
🔌 Test
ssh -T git@github.com
Output:
Hi username! You've successfully authenticated
4️⃣ Uploading the Project to the Server
cd /var/www/ai.kitmote.com
git clone git @github.com:USERNAME/REPO.git .
git clone git @github.com:USERNAME/REPO.git .
⚠️ Correct permissions
sudo chown -R www-data:www-data /var/www/ai.kitmote.com
sudo chmod -R 755 /var/www/ai.kitmote.com
sudo chmod -R 755 /var/www/ai.kitmote.com
Laravel exclusive:
chmod -R 775 storage bootstrap/cache
5️⃣ Laravel Installation Steps
📦 Addictions
composer install --no-dev --optimize-autoloader
⚙️ ENV
cp .env.example .env
nano .env
nano .env
🔑 Generate Key
php artisan key:generate
🗄️ Migration
php artisan migrate
⚡ Cache optimization
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan route:cache
php artisan view:cache
6️⃣ Production Recommendations
🔥 Queue (optional)
php artisan queue:work
Recommended with a supervisor.
🔍 Log check
tail -f storage/logs/laravel.log
🔄 Post-deployment update
git pull origin main
composer install --no-dev
php artisan migrate --force
PHP Artisan Optimize
composer install --no-dev
php artisan migrate --force
PHP Artisan Optimize
7️⃣ Common Mistakes
❌ 403 Forbidden
Is AllowOverride enabled?
Is Apache rewrite active?
❌ 500 Error
→ .env error
→ storage permissions
❌ 502 / blank page
Is Apache running?
sudo systemctl status apache2
🎯 Result
With this structure:
- ✅ Domain → VPS connected
- ✅ Apache → Laravel is running
- ✅ SSL → active
- ✅ GitHub → Automatic deployment ready
Keywords: VPS, SSH Key,