Skip to main content
⚡ OpenDevDocs
DevOps & Deployment
devopsdeploymentRecipeIntermediate

Deploy Laravel on Ubuntu VPS (LEMP + Queue Worker + Cron + SSL)

Production guide for hosting Laravel 11/12 on Ubuntu VPS with PHP 8.3-FPM, Nginx public root, Artisan optimization, systemd queue workers, and cron scheduler.

Verified: 2026-10-01
Tested on:laravel 11.x / 12.x, php 8.3, nginx 1.26
Platforms:
linuxall
#laravel#php#vps#queue-worker#cron#nginx

Goal

Deploy a production Laravel application on an Ubuntu VPS with optimized Artisan caching, background queue processing using systemd, automated task scheduling via Cron, and secure Nginx HTTPS.


git clone https://github.com/your-org/your-laravel-repo.git .

# Install production dependencies without dev packages
composer install --no-dev --optimize-autoloader

# Setup environment file
cp .env.example .env
php artisan key:generate

# Set storage and bootstrap/cache permissions for Nginx user (www-data)
sudo chown -R www-data:www-data /var/www/laravel-app/storage /var/www/laravel-app/bootstrap/cache
sudo chmod -R 775 /var/www/laravel-app/storage /var/www/laravel-app/bootstrap/cache

# Create public storage symlink
php artisan storage:link
```
# Cache configuration, routes, and Blade views
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
```
```nginx
server {
    listen 80;
    listen [::]:80;
    server_name laravel.example.com;

    # CRITICAL SECURITY: Root MUST point to the /public subdirectory!
    root /var/www/laravel-app/public;
    index index.php;

    client_max_body_size 50M;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
    }

    # Prevent downloading sensitive dotfiles (.env, .git)
    location ~ /\.(?!well-known).* {
        deny all;
    }
}
```

Enable and reload:
```bash
sudo ln -s /etc/nginx/sites-available/laravel.example.com.conf /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d laravel.example.com
```
```ini
[Unit]
Description=Laravel Queue Worker
After=network.target mysql.service

[Service]
User=www-data
Group=www-data
Restart=always
ExecStart=/usr/bin/php /var/www/laravel-app/artisan queue:work --sleep=3 --tries=3 --max-time=3600

[Install]
WantedBy=multi-user.target
```

Enable and start queue service:
```bash
sudo systemctl daemon-reload
sudo systemctl enable --now laravel-queue
```
Add the schedule runner line:
```cron
* * * * * cd /var/www/laravel-app && php artisan schedule:run >> /dev/null 2>&1
```

On this page