> ## Content Index
> Fetch the complete content index at: https://app.hostwolf.net/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Deploy a Laravel App to a VPS: Nginx, PHP-FPM, Migrations and Queues
- URL: https://app.hostwolf.net/blog/deploy-laravel-app-to-vps/
- Published: 2026-10-11T13:24:55.000Z
- Updated: 2026-10-11T13:24:58.000Z
- Description: A step-by-step production runbook for deploying Laravel on a VPS, with the failure modes that actually break deploys: 502s from socket mismatches, cached config hiding .env changes, stale queue workers and broken storage symlinks.
- Author: Hostwolf
- Tags: PHP & Laravel, Deploying, DevOps, VPS

Deploying Laravel to a VPS means installing PHP-FPM, pointing Nginx at `public/`, handling `.env` and config caching, running migrations non-interactively, and keeping queue workers and the scheduler alive across deploys. To deploy a Laravel app to a VPS well, you also need to know the failure modes that actually break deploys: 502s from socket mismatches, cached config hiding `.env` changes, stale workers running old code, and broken storage symlinks.

## What you need before you deploy a Laravel app to a VPS

Target stack: Ubuntu 24.04 with PHP 8.3 from the default repositories. [Laravel's official requirements](https://laravel.com/docs/12.x/deployment?ref=app.hostwolf.net) are PHP >= 8.2 plus extensions including Ctype, cURL, DOM, Fileinfo, Mbstring, OpenSSL, PCRE, PDO, Tokenizer and XML. Ubuntu 24.04 ships PHP 8.3, so that's the practical choice ([nrpcloud](https://nrpcloud.com/blog/how-to-install-laravel-on-ubuntu-24-04?ref=app.hostwolf.net)). If you need a newer patch release, the Ondřej Surý PPA (`sudo add-apt-repository ppa:ondrej/php -y && sudo apt update`) is the usual route, though the stock 8.3 packages are fine for most people.

Install FPM, CLI, and the extensions:

```bash
sudo apt update
sudo apt install php8.3-fpm php8.3-cli php8.3-common \
  php8.3-mysql php8.3-mbstring php8.3-xml php8.3-bcmath \
  php8.3-curl php8.3-zip php8.3-gd php8.3-intl

```

On a PostgreSQL stack, swap `php8.3-mysql` for `php8.3-pgsql`. Verify with `php -v` and `systemctl status php8.3-fpm`. Also install Composer, nginx, and your database server or client.

Sizing baseline: a small Laravel app fits comfortably in 1 GB including FPM workers and a local database. A mature FPM worker sits at 30–80 MB resident, and each queue worker costs roughly the same even while idle; four workers at 80 MB is 320 MB before anything else runs ([deploymanage](https://deploymanage.com/blog/how-to-deploy-laravel-to-vps?ref=app.hostwolf.net)). Use those numbers when picking a VPS size, not a guess.

Checklist before you touch the server:

- Domain DNS pointed at the server's IP
- Composer installed
- Code reachable via Git
- Database created, credentials in hand

## Install and configure PHP-FPM for Laravel

The pool defaults mostly work, but a few values matter for Laravel. In `/etc/php/8.3/fpm/php.ini`:

- `memory_limit` — 256M is a sane floor for Laravel
- `upload_max_filesize` and `post_max_size` — if they're lower than what your forms send, you get 413 errors that look like application bugs
- `max_execution_time` — raise it if you have slow report endpoints
- `date.timezone` — set it explicitly; Laravel's scheduler and date handling depend on it

PHP-FPM runs as `www-data` on Ubuntu. That single fact determines every later permission decision: anything the web user must write (storage, bootstrap/cache) needs that group.

Now note the socket path, because this value is the source of most 502 errors later:

```bash
ls -l /run/php/

```

On Ubuntu 24.04 you'll see something like `/run/php/php8.3-fpm.sock`. Write it down. Copying a `fastcgi_pass` line from an older server or a blog post with a different PHP version is the single most common cause of a 502.

Before the real app is deployed, verify FPM is actually serving. Drop a minimal file in a temp directory and a temporary Nginx location block that passes it to FPM:

```php
<?php phpinfo();

```

If that renders, FPM and Nginx are talking. Delete the temp file and remove the temporary location block afterward.

## Nginx server block: use Laravel's official pattern

Start from [Laravel's official deployment docs](https://laravel.com/docs/12.x/deployment?ref=app.hostwolf.net), which provide a canonical server block (they note it "most likely will need to be customized"). Adapted for PHP 8.3:

```nginx
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /var/www/example.com/public;

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

    index index.php;
    charset utf-8;

    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;
    }
}

```

The critical detail is `location ~ ^/index\.php(/|$)` instead of the common `location ~ \.php$` you see in third-party guides. The generic regex executes any `.php` file found under the root. The official pattern only executes the front controller. With a generic block, an uploaded or accidentally committed PHP file becomes remotely executable. There is no reason to accept that risk.

Two rules from the docs worth repeating verbatim: never move `index.php` to the project root. Serving the application from the project root will expose sensitive configuration files (`.env` included) to the public Internet. And the root must point at `public/`, never at the project root.

Enable and reload:

```bash
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

```

## Get the code on the server and set permissions correctly

Create a dedicated deploy user and clone as that user:

```bash
sudo adduser deploy
sudo usermod -aG www-data deploy
sudo -u deploy git clone git@github.com:you/example.com.git /var/www/example.com

```

Use this permission scheme ([vividvps](https://vividvps.com/deploy-laravel-vps/?ref=app.hostwolf.net)), and no `chmod -R 777` anywhere:

```bash
cd /var/www/example.com
sudo chown -R deploy:www-data .
sudo find . -type f -exec chmod 640 {} \;
sudo find . -type d -exec chmod 750 {} \;
sudo chmod 2770 storage bootstrap/cache
sudo chmod 640 .env

```

The `2` in `2770` is the setgid bit: new files created inside `storage/` and `bootstrap/cache/` inherit the `www-data` group, so permission drift doesn't accumulate over deploys. When you get a write error later, the group is wrong. Fix the group, don't loosen permissions.

On that point: `chmod -R 777` is the most common bad fix for storage errors, called out by multiple independent guides, and a frequent cause of blank 500s on fresh deploys. World-writable application directories are also an obvious security hole.

Finally, the public storage symlink:

```bash
php artisan storage:link

```

This creates `public/storage` pointing at `storage/app/public`. It is a real symlink, and it does not survive SFTP-style overwrites of `public/`, which is why images 404 after deploys where someone uploaded files that way. Re-run `storage:link` as part of every deploy (the script below does). If your environment forbids symlinks entirely, the fallback is a `FILESYSTEM_DISK` configuration with the root inside `public/` ([renode](https://www.renode.space/blog/deploy-laravel-to-production?ref=app.hostwolf.net)).

## .env, APP\_KEY and config caching done right

Never commit `.env`. Options for getting it onto the server:

- Copy it by hand when moving hosts (scp, not Git), updating DB credentials
- `php artisan env:encrypt` produces a committable `.env.encrypted` if you can accept the decryption key becoming the secret to protect
- Inject real environment variables instead; once config is cached, `env()` reads system-level variables, so CI/CD pipelines can supply secrets without a file

For a fresh install, `php artisan key:generate --force`. Keep the existing key when moving hosts: rotating `APP_KEY` invalidates every encrypted value and session in the database.

Set `APP_DEBUG=false` in production. Enabling debug to diagnose a 500 exposes configuration values to end users. Read `storage/logs/laravel.log` instead.

Then the trap that bites everyone once: `php artisan optimize` caches config, routes, views and events. After that, `.env` is not loaded, and `env()` outside the `config/` directory returns null ([Laravel docs](https://laravel.com/docs/master/deployment?ref=app.hostwolf.net)). This is the root cause of "I changed `.env` and nothing happened". The fix:

```bash
php artisan optimize:clear
php artisan optimize

```

And in application code, read values via `config()`, never `env()`.

## Migrations in production: --force, backups and multi-server

Non-interactive migrations against a production environment abort with `APPLICATION IN PRODUCTION.`. The documented fix is `--force`, which also bypasses the destructive-migration confirmation prompt ([Laravel migrations docs](https://laravel.com/framework/docs/migrations?ref=app.hostwolf.net)). That means `--force` runs dangerous SQL without asking, so wrap it:

1. Take a database backup before running `migrate --force`. Destructive migrations drop data. This is the step every guide recommends and most readers skip.
2. Preview the SQL with `php artisan migrate --pretend`.
3. If a migration fails halfway, check the `migrations` table to see what actually recorded before retrying.

`migrate:fresh` drops all tables then re-migrates. It is a rebuild tool for development, not a deploy step. If you seed in production, `db:seed --force` gets past the same production prompt.

On multi-server deploys, `php artisan migrate --isolated` acquires an atomic lock via the default cache driver; concurrent runs on other servers skip cleanly and exit 0\. It requires a shared central cache (redis, memcached, database, etc.) across all servers. To be precise about what this does: it prevents concurrent migration runs. It is not a zero-downtime feature, and it doesn't make schema changes backward-compatible.

For backward compatibility, write migrations expand-and-contract: add new columns and tables first, deploy code that works with both old and new schema, then remove old columns in a later release. That way a queue worker running during a deploy never hits a half-migrated schema.

## Queue workers with Supervisor: config that survives deploys

![Four glowing orange and periwinkle process slots with circular refresh motifs connected to a central recycling icon on…](https://app.hostwolf.net/blog/content/images/2026/10/deploy-laravel-app-to-vps-img-supervisor.webp)

A dark, geometric illustration of four glowing process slots with refresh arrows surrounding a central recycle motif.

Install Supervisor and a complete program config at `/etc/supervisor/conf.d/laravel-worker.conf`:

```ini
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/example.com/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/var/www/example.com/storage/logs/worker.log
stopwaitsecs=3600

```

Three details people get wrong:

- **Absolute paths.** Supervisor doesn't run a login shell, so there's no `$PATH`. `command=php ...` fails with a missing-PHP error unless you write the full path (find it with `which php`).
- **stopwaitsecs.** This is how long Supervisor waits after SIGTERM before sending SIGKILL. Laravel treats SIGTERM as finish-current-job-then-exit, so `stopwaitsecs` must exceed your longest job and the worker's `--timeout`, or jobs get hard-killed mid-run. It is the most commonly misconfigured Supervisor setting.
- **numprocs.** Size it to what your CPU and database connections can actually feed, not to a number from a blog post.

Use `queue:work`, never `queue:listen`, in production; `queue:listen` reboots the framework per job. `--tries=3` stops infinite retry loops and sends failures to the `failed_jobs` table, recoverable with `php artisan queue:retry all`. `--max-time=3600` recycles workers hourly, the cheapest defence against a slow memory leak in a package you don't control.

Apply the config:

```bash
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*

```

If jobs never run, check `systemctl status laravel-worker` (Supervisor registers itself as a service) and the worker log.

One honest trade-off: Laravel's docs use Supervisor, but systemd is already installed and one fewer package to patch. Either works. Pick one and be consistent across your servers.

## Deploy the Laravel app to a VPS: the scheduler cron entry and deploy script

The scheduler needs exactly one cron entry, run as the deploy user (`sudo -u deploy crontab -e`):

```
* * * * * cd /var/www/example.com && php artisan schedule:run >> /dev/null 2>&1

```

`schedule:run` fires every minute and Laravel decides internally which tasks are due. `schedule:work` is for local development only.

When scheduled tasks never fire, the cause is almost always one of: the entry is missing, it's under the wrong user's crontab, the path is wrong, or `php` doesn't resolve in cron's minimal PATH (use the absolute path there too). Verify with `crontab -l` and `php artisan schedule:list`. Add `->withoutOverlapping()` to long-running tasks and `->onOneServer()` when running multiple app servers.

The deploy script, in order, as a maintenance-mode walkthrough:

```bash
php artisan down --secret="deploy-2025"
git pull --ff-only
composer install --no-dev --optimize-autoloader
pg_dump "$DATABASE_URL" > ~/backups/pre-migrate-$(date +%F-%H%M).sql   # or mysqldump on MySQL
php artisan migrate --force
php artisan storage:link
php artisan optimize
php artisan queue:restart
php artisan up

```

The `pg_dump` line is the backup step from the migrations section made concrete: take it before every `migrate --force`, because `--force` skips the destructive-migration prompt. On MySQL, use `mysqldump` instead.

`queue:restart` is mandatory on every deploy. Workers hold old code in memory until restarted, so a skipped restart means the old buggy version keeps processing jobs after you've shipped the fix. It writes a timestamp to the cache (which is why it needs a working cache driver), workers finish their current job, exit, and Supervisor restarts them with fresh code.

To be plain about what this is: maintenance-mode deployment, not true zero-downtime. Users see the down page during the window. Real zero-downtime requires rolling deploys across multiple servers, which is a different project.

## Troubleshooting table: the failures every Laravel deploy hits

| Symptom                          | Likely cause                                                | Check                                                    |
| -------------------------------- | ----------------------------------------------------------- | -------------------------------------------------------- |
| 502 Bad Gateway                  | FPM not running, or fastcgi\_pass socket path doesn't match | systemctl status php8.3-fpm, ls -l /run/php/             |
| 500 after deploy                 | Stale cache or missing .env value with APP\_DEBUG=false     | storage/logs/laravel.log; never enable debug to diagnose |
| 404s that work locally           | Nginx root points at project root instead of public/        | check the root directive                                 |
| 404s on routes that should exist | Stale route cache                                           | php artisan route:list                                   |
| Class not found                  | Missing PHP extension                                       | php -m                                                   |
| Composer install fails           | PHP version, missing extension, or memory                   | composer diagnose, php -v, free -m                       |
| Images 404 after deploy          | Broken public/storage symlink                               | re-run php artisan storage:link                          |

Two more worth memorizing: scheduled tasks never fire points at the cron entry or PATH (see above), and jobs running old code points at a missed `queue:restart`.

## Where a GitHub-based platform removes these steps

This runbook works, and there's value in knowing it. But notice how many steps are drift-prone: the setgid bits, the symlink, the cron entry, the Supervisor config, `queue:restart` in the deploy script. Each one is easy to forget at 11 pm during a real deploy, and each one produces a failure that looks like an application bug.

Hostwolf Apps builds and runs web apps from a GitHub repository, with HTTPS on a configured domain, on a dedicated server per customer (a plain VPS option is also available). PostgreSQL and other databases come with scheduled backups, configurable retention and optional S3 storage, which covers the pre-migrate backup step that guides recommend and readers skip. Environment variables replace hand-copied `.env` files, and the deployment logs show you exactly what the build and deploy actually ran.

For teams that want this runbook automated, see the current catalog at [https://app.hostwolf.net/#pricing](https://app.hostwolf.net/?ref=app.hostwolf.net#pricing). For teams that want full control, every manual step above applies to any plain VPS.

## A short checklist to keep

If you take nothing else from this: check the FPM socket path on every new server, run `optimize:clear` before assuming `.env` changed anything, back up before `migrate --force`, put `queue:restart` in the deploy script, and never fix a permission error with 777\. Those five habits prevent most of the Laravel deploy failures documented in the wild.

## Frequently asked questions

### Why does my Laravel deploy show 502 Bad Gateway?

Almost always PHP-FPM: the php8.3-fpm service is not running or the fastcgi\_pass socket path in Nginx does not match the real socket in /var/run/php/. Check systemctl status php8.3-fpm and ls -l /run/php/. Copying a fastcgi\_pass line between servers or PHP versions is the single most common cause.

### Why do my .env changes have no effect in production?

After php artisan optimize, the config is cached and .env is not loaded, so env() outside the config/ directory returns null. Run php artisan optimize:clear followed by optimize, or read the value via config() instead of env().

### Is chmod -R 777 an acceptable fix for storage permission errors?

No. It is the most common wrong answer and a frequent cause of blank 500s. Fix the group instead: a dedicated deploy user in the www-data group, 2770 with the setgid bit on storage/ and bootstrap/cache/, and 640 on .env.

### Can I run migrations non-interactively in production?

Yes, with php artisan migrate --force. Without it, non-interactive runs against a production environment abort with the APPLICATION IN PRODUCTION prompt. Take a backup first and preview with migrate --pretend, since --force also bypasses the destructive-migration warning.

### How much memory does a Laravel VPS need?

A small Laravel app is comfortable in 1 GB including FPM workers and a local database. Mature FPM workers sit at 30–80 MB resident, and each queue worker costs roughly the same even while idle — four workers at 80 MB is 320 MB before anything else runs.