Kritim Yantra
Jun 17, 2025
Deploying a Laravel 12 project with a Vue 3 frontend (using Vite) on shared hosting might feel like launching a rocket — confusing buttons, too many wires. But don’t worry! In this guide, we’ll make this mission super simple.
By the end, your Laravel + Vue 3 app will be live on shared hosting — working beautifully with Vite assets, SPA routing, and all.
Before diving in, make sure you have:
Let’s start by compiling the Vue 3 frontend using Vite.
Run this in your Laravel project root:
npm run build
This will generate a dist/
folder (or whatever path you’ve set) under resources/js
or resources/vue
.
Let’s say you’ve configured the Vite build output to go to public/vue
.
You’ll see a structure like this:
public/
├── vue/
│ ├── index.html
│ ├── assets/
│ └── js/
Add this fallback route in your routes/web.php
:
use Illuminate\Support\Facades\Route;
Route::get('/{vue_capture?}', function () {
return file_get_contents(public_path('vue/index.html'));
})->where('vue_capture', '.*');
📌 What this does: It tells Laravel to serve vue/index.html
for any route not matched earlier — allowing Vue Router to take over. Perfect for SPAs.
Here’s how to structure your files on shared hosting:
Shared hosting usually serves files from the public_html/
folder.
Here's how to place your files:
public_html/ <-- Laravel's "public" folder contents go here
├── index.php
├── vue/
├── js/
├── css/
...
your-laravel-project/ <-- All other Laravel files
├── app/
├── bootstrap/
├── routes/
├── vendor/
If you can’t place Laravel root outside public_html
, move everything inside public_html/laravel
and keep only public files in root.
Then, edit index.php
in public_html/
like this:
require __DIR__.'/laravel/vendor/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
✅ Upload your .env
file and configure it:
APP_ENV=production
APP_KEY=your-key-here
APP_DEBUG=false
APP_URL=https://yourdomain.com
✅ Give correct permissions (use File Manager or SSH):
storage/
and bootstrap/cache/
should be writable.✅ Don’t forget to run:
php artisan config:cache
php artisan route:cache
php artisan view:cache
.htaccess
for Pretty URLsIf your shared hosting uses Apache (most do), ensure your .htaccess
inside public_html/
contains:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
This ensures both Laravel and Vue routes work nicely without 404 errors.
This is how your public/vue/index.html
might look:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Vue 3 SPA</title>
<link rel="stylesheet" href="/vue/assets/app.css">
<script type="module" src="/vue/assets/app.js"></script>
</head>
<body>
<noscript>Please enable JavaScript to run this app.</noscript>
<div id="app"></div>
</body>
</html>
✅ Make sure asset paths are relative (/vue/assets/...
) or absolute to prevent 404 on refresh.
Think of Laravel as your backend engine, and Vue as your car’s dashboard. Laravel powers everything under the hood, while Vue makes it look modern and interactive.
When deployed properly, your users will see a smooth dashboard (Vue), and your Laravel engine will handle the business logic — fast and silent in the background.
Before calling it a day, double-check:
Task | Done |
---|---|
npm run build done for Vue |
✅ |
Route fallback to vue/index.html |
✅ |
Laravel files uploaded | ✅ |
public/ content placed in public_html/ |
✅ |
.env configured |
✅ |
storage/ permissions set |
✅ |
.htaccess for clean URLs |
✅ |
Deploying Laravel 12 with Vue 3 (Vite) on shared hosting is not as scary as it sounds.
With a clear structure and proper routing setup, you can enjoy the power of a full-stack SPA app — even on budget hosting.
Now go ahead and launch your Laravel + Vue rocket 🚀 into the internet sky.
Transform from beginner to Laravel expert with our personalized Coaching Class starting June 26, 2025. Limited enrollment ensures focused attention.
1-hour personalized coaching
Build portfolio applications
Industry-standard techniques
Interview prep & job guidance
Complete your application to secure your spot
Thank you for your interest in our Laravel mentorship program. We'll contact you within 24 hours with next steps.
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google