Home > Enterprise >  How do I get Laravel assets to work in production, works fine in dev?
How do I get Laravel assets to work in production, works fine in dev?

Time:06-23

I have a header blade:

<link href="{{ asset('css/custom.css') }}" rel="stylesheet">

When i load my page on the prod server, i see this in page source:

<link href="public/css/custom.css" rel="stylesheet">

On my dev server, I was getting:

<link href="https://myserver.com/css/custom.css" rel="stylesheet">

This worked fine in dev, but on prod, I am getting 404 on the custom.css file.

Even if i enter the url:

https://myserver.com/css/custom.css

I get a 404.

some possibly releveant env settings:

APP_ENV=production
APP_URL=https://myserver.com

Some logs from dev:

[23/Jun/2022:01:16:23 -0400] "GET /css/custom.css HTTP/1.1" 200 528 "https://myserver.com/" 
[23/Jun/2022:01:16:23 -0400] "GET /js/myJs.js HTTP/1.1" 200 162 "https://myserver.com/" 
[23/Jun/2022:01:16:23 -0400] "GET /css/app.css HTTP/1.1" 200 205348 "https://myserver.com/"

from prod:

[23/Jun/2022:01:15:17 -0400] "GET /css/app.css HTTP/1.1" 404 
[23/Jun/2022:01:15:17 -0400] "GET /css/custom.css HTTP/1.1" 404
[23/Jun/2022:01:15:17 -0400] "GET /js/myJs.js HTTP/1.1" 404 

CodePudding user response:

apache vhost config was not correct:

DocumentRoot /var/www/html/secreport/public/index.php

should be:

DocumentRoot /var/www/html/secreport/public

CodePudding user response:

Use,

<link rel="stylesheet" href="{{ mix('css/app.css')}}" type="text/css">
  • Related