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

Leff7's avatar
Level 4

Laravel routes and css or js links are not working on production server

I have a laravel project, which is working fine on the local machine, where I have it set up on homestead, but when I have uploaded project to the production server on namecheap, none of the links or routes are working, I only get the index page open with no style, and if I click on any of the links I get 500 error. I have follow the suggested steps here:

So, my laravel project directory is in the same level as public_html, as well as public directory from my laravel project. They are all in the same directory level. And I have changed the paths in the index.php file:

require __DIR__.'/mariva/bootstrap/autoload.php';
$app = require_once __DIR__.'/mariva/bootstrap/app.php';

Then, I have changed the server.php inside the laravel project directory:

require_once __DIR__.'../public_html/index.php';

In the view file I am calling my css files like this:

<!-- CSS Files -->
  <link href="{{ asset('css/material-kit/css/bootstrap.min.css') }}" rel="stylesheet" />
  <link href="{{ asset('css/material-kit/css/material-kit.css') }}" rel="stylesheet"/>
  <link href="{{ asset('css/landing-page.css') }}" rel="stylesheet"/>

And js file the same way:

<!--   Core JS Files   -->
<script src="{{ asset('js/landing-page/jquery.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/landing-page/bootstrap.min.js') }}" type="text/javascript"></script>
<script src="{{ asset('js/landing-page/material.min.js') }}"></script>

<!-- Control Center for Material Kit: activating the ripples, parallax effects, scripts from the example pages etc -->
<script src="{{ asset('js/landing-page/material-kit.js') }}" type="text/javascript"></script>

Permission were set apparently by the namecheap customer service, but I still get 404 error for all my css and js files, as well as when clicking on some html links on my page.

Not sure how can I fix that?

0 likes
9 replies
tomopongrac's avatar

can you show us how your code where you import css and javascrip ...

maybe you did't put slash on begining

"/folder/where/your_css_is.css"
RonB1985's avatar

Are you using asset links? These should always work.

<link href="{{ asset('css/app.css') }}" rel="stylesheet">
Leff7's avatar
Level 4

I am ussing asset and the links are correct since it is working fine on local server, it is just that is not working on production server.

Snapey's avatar

maybe now you have published into a sub-folder?

e.g. yourdomain.com/public/index.php

beorn's avatar

I have the same problem, have you managed to solve your issue ?

I think the problems comes from fastcgi but i am not sure.

Let me know if you find something, I will also post if I can fix it.

1 like
ZahidGopang's avatar

how did solved this brother as i am getting this error right

ZahidGopang's avatar

what was the solution of this query as i am getting this same on laravel 8 , i just deployed it on linux ec2 now my css and js files are not being loaded

dimkiriakos's avatar

Solution 1: If you are a guy like me (I'm deploying to shared hosting small and intermediate applications) got to Cpanel or to Plesk and change all inside the public folder and subfolders to 755 or higher. Solution 2: Now in the case of a kind of dedicated server like VPS, Cloud, etc that you have root permissions check of course the folder's permissions as above but I would suggest you to dockerize your app to be sure that it will work everywhere. here is the official documentation how to dockerize your app https://laravel.com/docs/8.x/sail

Please or to participate in this conversation.