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

adrians's avatar
Level 10

Laravel Envoyer on Vps

Hello there. I want to deploy an app on a VPS that handles many domains. I dont want to install the app in public_html so my dir structure is: /home/domain_name/app_name /home/home_name/public_html I cannot not change the document root (public_html) to app/public because of server restrictions. I can reference to the app from public_html/index.php (no need to change between deployments), but the vite build changes. Now the assets(js,css) are reference from public_html, not public folder of the app. Thnx for any suggestions.

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue of deploying a Laravel application on a VPS where you cannot change the document root from public_html to app/public, you can follow these steps to ensure that your assets are correctly referenced and served.

Step-by-Step Solution

  1. Symlink the Public Directory: Create a symbolic link from the app/public directory to the public_html directory. This way, the assets will be served correctly from the public_html directory.

    ln -s /home/domain_name/app_name/public /home/home_name/public_html/public
    
  2. Update the index.php File: Modify the index.php file in the public_html directory to point to the correct paths for the Laravel application.

  3. Configure Vite: Ensure that Vite is configured to output assets to the correct directory. Update your vite.config.js to set the correct outDir.

    import { defineConfig } from 'vite';
    import laravel from 'laravel-vite-plugin';
    
    export default defineConfig({
        plugins: [
            laravel({
                input: ['resources/js/app.js', 'resources/css/app.css'],
                refresh: true,
            }),
        ],
        build: {
            outDir: '../public_html/public/build',
            emptyOutDir: true,
        },
    });
    
  4. Update Asset URLs: Ensure that your asset URLs in your Blade templates are correctly referencing the public_html/public directory.

    <link rel="stylesheet" href="{{ asset('public/build/app.css') }}">
    <script src="{{ asset('public/build/app.js') }}" defer></script>
    

By following these steps, you should be able to deploy your Laravel application on a VPS with the given directory structure and ensure that your assets are correctly referenced and served.

Please or to participate in this conversation.