Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muazzamazaz's avatar

Laravel Vite Path Issue at host server

I am running application using vite/vue & Laravel 9 and its working fine at localhost but when same machine is being accessed via http://IP_ADDRESS/fms/public it gets change path to http://IP_ADDRESS/fms/public/fms/public after login. In results some pages get broken and don't find the path of the build files that are located inside /fms/public/build and gives me following error:

http://IP_ADDRESS/build/assets/Dashboard.d690d20e.js net::ERR_ABORTED 404 (Not Found)

Please tell me what isssu is?

0 likes
5 replies
LaryAI's avatar
Level 58

The issue seems to be related to the base URL of the application. When accessing the application via the IP address, the base URL is set to /fms/public, but when accessing it locally, the base URL is just /. This causes the paths to be incorrect when accessing the build files.

To fix this, you can set the base URL dynamically based on the current environment. In your Laravel configuration file, you can add the following code:

// config/app.php

return [
    // ...
    'url' => env('APP_URL', 'http://localhost'),
    'asset_url' => env('ASSET_URL', null),
    // ...
];

Then, in your Vue app, you can set the base URL dynamically based on the Laravel configuration:

// resources/js/app.js

import { createApp } from 'vue';
import App from './App.vue';

const app = createApp(App);

const baseUrl = document.querySelector('meta[name="base-url"]').getAttribute('content');
app.config.globalProperties.$baseUrl = baseUrl;

app.mount('#app');

Finally, in your HTML layout file, you can add a meta tag to set the base URL:

<!-- resources/views/layouts/app.blade.php -->

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="base-url" content="{{ url('/') }}">
        <title>My App</title>
    </head>
    <body>
        <div id="app"></div>
        <script src="{{ mix('js/app.js') }}"></script>
    </body>
</html>

This should set the base URL correctly and allow the build files to be loaded correctly.

Snapey's avatar
Snapey
Best Answer
Level 122

make sure your document root is correctly set as the public folder

Following Lary's advice is leaving you with a very unsafe site

just for laughs, visit http://ip_address/fms/.env

Please or to participate in this conversation.