Host Behind Nginx

Introduction

When moving from php artisan serve to a local Nginx/PHP-FPM stack or a production deployment, you must ensure your environment variables and file permissions are correctly configured.

Step 1 — Directory Permissions

Ensure the web server user (e.g., www-data or nginx) has write permissions to the storage and bootstrap/cache directories.

bash
chown -R www-data:www-data storage bootstrap/cache

If you are using the default SQLite database, the web server must also have write access to both the database file *and the directory containing it* to write the WAL files.

bash
chown www-data:www-data database/
chown www-data:www-data database/database.sqlite

Step 2 — Configuring Vite HMR

If you are running the Vite development server (npm run dev) behind an Nginx proxy, set the origin and port in your .env file so the hot-module replacement websocket connects successfully:

env
VITE_DEV_SERVER_PORT=5173
VITE_DEV_SERVER_ORIGIN=http://my-app.test:5173

Ensure your Nginx vhost proxies /vite-hmr to the correct Vite port.

Was this page helpful?

Source: xuple/evodevops/resources/js/pages/docs/evolayer-base/how-to/host-behind-nginx.tsx