Deploy Laravel on shared hosting

 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:

  1. Move everything inside the public/ folder (e.g. index.php, build/, css/, js/, etc.) into the root directory (same place as .env).

  2. Then open index.php and update the paths to bootstrap Laravel properly:


// index.php require __DIR__ . '/vendor/autoload.php'; $app = require_once __DIR__ . '/bootstrap/app.php';

Replace this:


require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';

Basically, remove ../ from both paths so they look in the current directory (since you moved index.php).


✅ 5. Update Vite paths if needed

In vite.config.js, make sure your base is / like this:


export default defineConfig({ plugins: [laravel({ input: ['resources/css/app.css', 'resources/js/app.js'], refresh: true, })], base: '/', // important });

Then run npm run build again and re-upload public/build.


✅ 6. Composer install on server

If you have SSH access:


composer install --no-dev --optimize-autoloader php artisan config:cache php artisan route:cache php artisan view:cache

Otherwise, do this on local and upload the vendor/ folder.


✅ 7. Set correct permissions

Make sure storage/ and bootstrap/cache/ are writable:


chmod -R 775 storage bootstrap/cache

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:

StepDescription
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

Pages