Application Hosting15 min read•Updated November 2026

How to Deploy a Laravel Application on a VPS with Nginx and PHP-FPM

Quick answer

To deploy Laravel on a VPS: install Nginx, PHP-FPM with the required extensions, Composer and a database; clone the app, run composer install --no-dev --optimize-autoloader, set up .env and php artisan key:generate, and make storage and bootstrap/cache writable by the web user. Point Nginx's root at the public directory with try_files $uri $uri/ /index.php?$query_string, cache config and routes, run queue workers under systemd and the scheduler from cron, then add HTTPS with Certbot.

Laravel runs well on a single VPS, and you get full control over PHP versions, workers and caching that shared hosting cannot offer. A correct production setup needs a few things that local development hides: PHP-FPM tuned for your memory, the web root pointing at public/ only, correct file permissions, cached configuration, and long-running queue workers that restart cleanly on deploy. This guide covers each of them on Ubuntu 24.04.

Step 1: Check PHP Version Requirements

Recent Laravel releases require PHP 8.2 or newer. Ubuntu 24.04 ships PHP 8.3 in its repositories, which is suitable. Ubuntu 22.04 ships PHP 8.1, which is too old for current Laravel; on that release, use a third-party PHP repository or upgrade the OS. Always confirm the requirement for your Laravel version in its upgrade guide.

Step 2: Install Nginx, PHP-FPM and Extensions

sudo apt update
sudo apt install -y nginx git unzip \
  php8.3-fpm php8.3-cli php8.3-mbstring php8.3-xml php8.3-curl \
  php8.3-zip php8.3-bcmath php8.3-intl php8.3-mysql php8.3-redis
php -v

Use php8.3-pgsql instead of php8.3-mysql for PostgreSQL. Install Composer from the official installer (verify the installer hash shown on getcomposer.org) or from the distribution package composer.

Install your database (for example sudo apt install -y mysql-server or mariadb-server), create a database and a user with a strong password, and keep it bound to localhost.

Step 3: Deploy the Application

sudo mkdir -p /var/www/app
sudo chown $USER:www-data /var/www/app
git clone https://github.com/your-org/app.git /var/www/app
cd /var/www/app
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate

Edit .env for production:

APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=app
DB_USERNAME=app
DB_PASSWORD=use-a-long-random-password

CACHE_STORE=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

APP_DEBUG=false is essential: debug pages expose environment variables, including database passwords. Restrict the file: chmod 640 .env, owned by your deploy user with group www-data. Variable names change between Laravel versions (for example CACHE_DRIVER became CACHE_STORE), so copy names from your own .env.example.

Step 4: Set File Permissions

PHP-FPM runs as www-data. It must write to storage/ and bootstrap/cache/, and should only read everything else:

cd /var/www/app
sudo chown -R $USER:www-data .
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
chmod 640 .env

Never use chmod -R 777. It lets any process on the server modify your code.

Step 5: Migrate and Cache

php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache

After config:cache, Laravel no longer reads .env at runtime, and env() calls outside config files return null. Read environment values only inside config/*.php and use config() in your code. Re-run the cache commands after every deploy.

Step 6: Configure Nginx

This configuration follows the one in Laravel's deployment documentation. Create /etc/nginx/sites-available/app:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/app/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;
    charset utf-8;
    client_max_body_size 20m;

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

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

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

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx

Two details matter for security. The root points at public/, so .env, vendor/ and storage/ can never be downloaded. Only index.php is passed to PHP, so an uploaded .php file elsewhere cannot execute.

Step 7: Tune PHP-FPM and OPcache

The pool file is /etc/php/8.3/fpm/pool.d/www.conf. The key setting is pm.max_children, which caps concurrent PHP processes and therefore memory:

pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500

Estimate it as RAM you can give PHP ÷ average memory per child. Check real usage with ps -o rss= -C php-fpm8.3 | awk '{s+=$1} END {print s/NR/1024 " MB"}'. On an 8 GB server that also runs MySQL and Redis, 4–5 GB for PHP at roughly 60 MB per child gives about 70 children; start lower and raise it while watching free -h.

OPcache is enabled by default in PHP-FPM. For production, in /etc/php/8.3/fpm/conf.d/10-opcache.ini set opcache.memory_consumption=256 and opcache.validate_timestamps=0, then reload PHP-FPM on each deploy so new code is picked up:

sudo systemctl reload php8.3-fpm

Step 8: Run Queue Workers with systemd

Queue workers are long-running processes, so supervise them. Create /etc/systemd/system/laravel-worker@.service:

[Unit]
Description=Laravel queue worker %i
After=network.target redis-server.service mysql.service

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

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now laravel-worker@1 laravel-worker@2

Workers keep your code in memory, so they must restart after a deploy. php artisan queue:restart tells them to exit after finishing the current job, and systemd starts fresh ones. Supervisor is a common alternative to systemd and is what Laravel's documentation uses; either is fine. Laravel Horizon is a good option if you use Redis queues heavily.

Step 9: Enable the Scheduler

Laravel's scheduler needs a single cron entry that runs every minute:

sudo crontab -u www-data -e
* * * * * cd /var/www/app && /usr/bin/php artisan schedule:run >> /dev/null 2>&1

The individual tasks and their timing live in your code. Our cron guide explains why absolute paths matter here.

Step 10: Enable HTTPS

sudo ufw allow 'Nginx Full'
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d example.com -d www.example.com

Behind a proxy or load balancer, configure Laravel's trusted proxies so generated URLs use https. With Nginx on the same server terminating TLS, PHP receives HTTPS=on via fastcgi_params and no extra setup is needed.

A Repeatable Deploy Script

#!/usr/bin/env bash
set -euo pipefail
cd /var/www/app
php artisan down --retry=60
git pull --ff-only
composer install --no-dev --optimize-autoloader --no-interaction
php artisan migrate --force
php artisan config:cache && php artisan route:cache && php artisan view:cache
sudo systemctl reload php8.3-fpm
php artisan queue:restart
php artisan up

php artisan down shows a maintenance page during the deploy. For true zero downtime, deploy each release into its own directory and switch a current symlink, which is what tools such as Deployer and Envoyer automate.

SkyRainCloud Plans for This Workload

PHP-FPM memory is the main sizing factor: each child process typically uses 30–80 MB. A Laravel app with MySQL and Redis fits 2 vCores / 8 GB; busy stores, multiple queue workers or several apps on one server need the 4 vCore / 16 GB tier.

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting

SymptomCause and fix
500 error with no detailsRead storage/logs/laravel.log and /var/log/nginx/error.log; often permissions on storage/
"Permission denied" writing logs or cacheRe-apply group www-data and ug+rwx on storage and bootstrap/cache
502 Bad GatewayPHP-FPM stopped or wrong socket path; systemctl status php8.3-fpm and check fastcgi_pass
Config changes not appliedRe-run php artisan config:cache
Jobs run old codeRun php artisan queue:restart after deploying
404 on every route except /Missing try_files ... /index.php?$query_string in Nginx

Frequently Asked Questions

Which PHP version do I need for Laravel?
Recent Laravel versions require PHP 8.2 or newer. Ubuntu 24.04 includes PHP 8.3, which works well. Check the exact requirement in the upgrade guide for your Laravel version.
Should I use Nginx or Apache for Laravel?
Both are supported. Nginx with PHP-FPM is the most common production setup and uses less memory under concurrency. Apache works with the .htaccess file Laravel ships in public/.
Why must the web root point to the public folder?
Only public/ is meant to be web-accessible. Pointing the root at the project directory would expose .env, source code and vendor/ to anyone who guesses the path.
What permissions does Laravel need?
The web server user (usually www-data) needs write access to storage/ and bootstrap/cache/ only. Everything else should be readable but not writable by it. Never use 777.
How do I run Laravel queues in production?
Run php artisan queue:work under systemd or Supervisor so it restarts automatically, and call php artisan queue:restart after each deploy so workers load the new code.
How do I set up the Laravel scheduler on a VPS?
Add one cron entry for the web user: * * * * * cd /var/www/app && php artisan schedule:run >> /dev/null 2>&1. Laravel decides which tasks are due each minute.
Why does env() return null in production?
After php artisan config:cache, the .env file is no longer loaded. Only call env() inside config files and read values with config() in application code.
How should I size pm.max_children?
Divide the memory available for PHP by the average PHP-FPM process size (measure it with ps). Leave room for the database, Redis and the OS. Too high a value causes swapping; too low causes requests to queue.
Can I host several Laravel apps on one VPS?
Yes. Give each app its own Nginx server block, database and, ideally, its own PHP-FPM pool running as a separate user, so one app cannot read another's files.
Which SkyRainCloud plan is right for Laravel?
A typical Laravel app with MySQL and Redis runs comfortably on the 2 vCore / 8 GB Intel or AMD EPYC plan. Choose 4 vCores / 16 GB for busy stores, several queue workers or multiple apps.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning