Knowledge Base
0 / 6 done
0%
Intermediate
~35 min
sudo required
Deploy a Laravel App on Ubuntu with Nginx + SSL
End-to-end guide: clone, configure Nginx, set up Let's Encrypt SSL, and run migrations for a production Laravel application.
Prerequisites
- Ubuntu server
- Domain name with DNS pointing to server
- Laravel project repository
1
Step 1
Command
Update system & install dependencies
apt update && apt upgrade -y apt install -y nginx php8.3-fpm php8.3-mbstring php8.3-xml php8.3-bcmath php8.3-curl php8.3-zip unzip git
2
Step 2
Command
Clone the Laravel project
git clone {{repo_url}} /var/www/html/app
cd /var/www/html/app
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
3
Step 3
Command
Set storage permissions
chown -R www-data:www-data /var/www/html/app/storage /var/www/html/app/bootstrap/cache chmod -R 775 /var/www/html/app/storage /var/www/html/app/bootstrap/cache
4
Step 4
Command
Create Nginx virtual host
# Copy the nginx-create-vhost snippet, save to /etc/nginx/sites-available/app.example.com ln -s /etc/nginx/sites-available/app.example.com /etc/nginx/sites-enabled/ nginx -t && systemctl reload nginx
5
Step 5
Command
Issue SSL certificate with Certbot
apt install certbot python3-certbot-nginx -y certbot --nginx -d app.example.com
6
Step 6
Command
Run migrations & cache config
cd /var/www/html/app php artisan migrate --force php artisan config:cache php artisan route:cache php artisan view:cache