Prerequisites
Laravel requires PHP 8.1+, Composer, a web server (Nginx recommended), and a database (MySQL/MariaDB or PostgreSQL).
Install Dependencies
sudo apt update
sudo apt install -y php8.2-fpm php8.2-mysql php8.2-mbstring php8.2-xml \
php8.2-curl php8.2-zip php8.2-bcmath php8.2-redis nginx mariadb-server
# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composerDeploy Your App
cd /var/www
git clone https://github.com/you/mylaravel.git
cd mylaravel
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_passwordNginx Configuration
server {
listen 80;
server_name example.com;
root /var/www/mylaravel/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;
}
location ~ /\.(?!well-known) {
deny all;
}
}Permissions and Optimization
sudo chown -R www-data:www-data storage bootstrap/cache
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache