Home > Software engineering >  Public folder not working with Mix and Asset Laravel Helpers Ubuntu 21.04
Public folder not working with Mix and Asset Laravel Helpers Ubuntu 21.04

Time:03-18

I am in the middle of creating a Laravel website, and have tested everything locally up to now and it has been working fine. I have set up a web server on a vps and have added the website to test that it the server is working. Everything in my public folder is not being picked up by the Laravel helper functions such as 'Mix' and 'Asset'.

This is how I would usually reference files locally, but for it to work on the server, I have to type the file path.

<!-- Styles -->        
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
{{-- <link rel="stylesheet" href="/public/css/app.css"> --}}

<!-- Scripts -->
<script src="{{ asset('js/navController.js') }}" defer></script>
{{-- <script src="/public/js/navController.js" defer></script> --}}

When I open up the console in my browser, it shows this error code.

GET http://domain.name/js/navController.js net::ERR_ABORTED 404 (Not Found)
GET http://domain.name/css/app.css net::ERR_ABORTED 404 (Not Found)

Using

  • Ubuntu Server 21.04
  • Laravel 8
  • LAMP (MySql)

CodePudding user response:

If /public appears in your URI, your site is misconfigured. The public/ dir should be the DocumentRoot, so that / in your browser shows the public/index.php file.

Here's an example of how to configure your document root in both Apache and nginx.

Lastly, a warning - serving your site out of the project root (as you are now) instead of public/ is a security risk and you shouldn't do that.

  • Related