Here’s a step-by-step guide to correctly deploy a Laravel Breeze + Vite project on shared hosting (e.g. Hostinger):
✅ 1. Build your assets locally
On your local machine, run:
npm install && npm run build
This will build your Vite assets into the public/build folder (assuming your Vite config is default).
✅ 2. Upload the project to Hostinger
Use FTP or File Manager to upload all Laravel files, except for the vendor/ and node_modules/ directories initially.
Upload these folders and files:
-
app/,bootstrap/,config/,database/,resources/,routes/,storage/,tests/, etc. -
.env,artisan,composer.json,vite.config.js, etc. -
public/contents (we’ll fix the path issue next).
❌ 3. Problem: Hostinger's root is not public/
Since Hostinger sets the document root to the project folder and not to public/, the correct approach is:
✅ 4. Move public/ contents to root and fix paths
Do this carefully:
-
Move everything inside the
public/folder (e.g.index.php,build/,css/,js/, etc.) into the root directory (same place as.env). -
Then open
index.phpand update the paths to bootstrap Laravel properly:
Replace this:
Basically, remove
../from both paths so they look in the current directory (since you movedindex.php).
✅ 5. Update Vite paths if needed
In vite.config.js, make sure your base is / like this:
Then run npm run build again and re-upload public/build.
✅ 6. Composer install on server
If you have SSH access:
Otherwise, do this on local and upload the vendor/ folder.
✅ 7. Set correct permissions
Make sure storage/ and bootstrap/cache/ are writable:
If you don’t have terminal access, do this via File Manager.
✅ 8. Set your .env properly
Make sure you update your .env file with the correct DB, mail, and APP_URL values (e.g., https://yourdomain.com).
Optional: Use a subdomain for /public
If your host allows changing the document root, you can point your main domain or a subdomain to /public. This is the most secure option but not possible on many shared hosts.
🛠️ Summary of What You Did:
| Step | Description |
|---|---|
| ✅ | Built Vite assets locally (npm run build) |
| ✅ | Moved public/ contents to root |
| ✅ | Fixed index.php paths |
| ✅ | Ensured vite.config.js uses correct base |
| ✅ | Set proper permissions and .env values |
f you want, I can provide a ready-to-use deployment checklist or script you can follow every time you update the project. Would that help?
No comments:
Post a Comment