Prerequisites
- A VPS running Ubuntu 22.04 or newer
- PHP 8.2+ with required extensions
- Nginx or Apache web server
- Composer
- MySQL/MariaDB or PostgreSQL
Install Dependencies
sudo apt update && sudo apt install -y php8.2-fpm php8.2-mysql php8.2-xml php8.2-mbstring php8.2-curl php8.2-zip php8.2-gd php8.2-redis unzip nginx mariadb-server
# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composerDeploy the Application
cd /var/www
git clone https://github.com/yourname/myapp.git
cd myapp
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generateConfigure Environment
Edit .env:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=myapp
DB_USERNAME=myapp_user
DB_PASSWORD=secure_passwordSet Permissions
sudo chown -R www-data:www-data /var/www/myapp
sudo chmod -R 755 /var/www/myapp/storage
sudo chmod -R 755 /var/www/myapp/bootstrap/cacheNginx Configuration
server {
listen 80;
server_name example.com;
root /var/www/myapp/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}Run Migrations and Optimize
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cacheQueue Worker (if needed)
# /etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
command=php /var/www/myapp/artisan queue:work --sleep=3 --tries=3
user=www-data
numprocs=2
autostart=true
autorestart=true