Nababur's avatar
Level 43

Vite does not work after deploying Laravel project on the server

build folder in public but the link does not generate with the public folder.

Not work original https://nababur.info/jobfinder/build/assets/app-5520e0f1.css

Here is the vite config file url:

@vite(['resources/sass/app.scss', 'resources/js/app.js'])

0 likes
10 replies
LaryAI's avatar
Level 58

It seems like the issue is with the generated link for the CSS file not including the "public" folder in the URL. To fix this, you can modify the Vite configuration file.

In your Vite configuration file, you can specify the publicDir option to tell Vite where your public folder is located. By default, Vite assumes the public folder is named "public". However, if your public folder has a different name, you need to specify it explicitly.

Here's an example of how you can modify your Vite configuration file to include the publicDir option:

import { defineConfig } from 'vite';

export default defineConfig({
  publicDir: 'public',
});

Make sure to replace 'public' with the actual name of your public folder if it's different.

After making this change, rebuild your project and deploy it again. The generated link for the CSS file should now include the "public" folder in the URL.

If you're still facing issues, please provide more details about your project setup and any error messages you're encountering.

vincent15000's avatar

Have you executed npm run build in the console ?

Either you execute this command locally and then you push the public/build folder to your repo.

Or you execyte this command directly on the production server.

1 like
JussiMannisto's avatar

@Nababur Your configuration is all wrong and your app is vulnerable. Anyone can read any file within your project, including your .env file.

You should immediately take your site down if it contains any sensitive information. Bots automatically scan /.env paths on websites due to misconfigurations like these.

1 like
Snapey's avatar

@Nababur clearly you found the WRONG way to deploy in cpanel, thus exposing your .env file.

1 like
JussiMannisto's avatar

@Nababur No, you've deployed the app incorrectly. You need to look for a tutorial on how to deploy the app in your environment. There are plenty of examples around the web, including this forum. But it all depends on your server environment.

If you configured the app correctly, you shouldn't need to move directories around like you did. I recommend you restore the original directory structure. Also make sure that you've configured your .env for production: your APP_ENV should be production and APP_DEBUG should be set to false. If APP_DEBUG is true on a live site, it's a huge security issue. Any exception will show the debug screen that contains all environment variables, so it's at least as bad as leaking the .env file.

2 likes

Please or to participate in this conversation.