Laravel routes are not working on production server 404 error
Asked Answered
S

4

7

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';

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.

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>

Not sure how can I fix that?

Update

I have managed to fix the css and js issue of not opening the files, I have moved the files to the wrong directory by mistake. But I still can't get any links on the page to work?

In my view I have links like this one:

<a href="{{ url('/login') }}">Login</a>

And when clicking on them I get 404 error.

Spread answered 16/1, 2017 at 14:9 Comment(3)
Is your server VPS? Do your .htaccess work?Rickettsia
are you deploy in share hosting or server dedicated?Tva
I am deploying on shared serverSpread
A
2

the problem may be in the trusted hosts

try setting this in your .env

APP_URL=http://
Artemis answered 31/7, 2021 at 2:2 Comment(1)
on the production env, not setting the APP_URL will result in 404 routes, that's weird but true!Quelpart
A
0

You need to set up Laravel project in shared hosting which is well explained here.

After you succeed thru all 7 steps your project should work fine on server.

Also add this to your .htacces file in public_html

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^ index.php [L]

Hope it helps

Apodaca answered 16/1, 2017 at 14:14 Comment(3)
Have you copied all content of public folder from Laravel to hosting folder public_html? Don't override index.php and .htacess files.Apodaca
I have copied all the content from public laravel folder to public_html folder, except for the .htacess file. I have modifed the existin .htacess file in public_html folder and added code you suggested, so it looks like this now: DirectoryIndex index.html index.php index.htm parking-page.html <IfModule mod_suphp.c> suPHP_ConfigPath /home/marigxwy/public_html </IfModule> Options +FollowSymLinks RewriteEngine On RewriteRule ^ index.php [L] But I still don't get any css and js links open.Spread
Remove all code from .htacces file and add just mine codeApodaca
M
0

Options -MultiViews

RewriteEngine On
RewriteBase /laravel51/public/

# change above to your site i.e., RewriteBase /whatever/public/

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

In .htaccess file has to change

Monro answered 25/11, 2017 at 11:25 Comment(0)
E
0

2024 - simply try clean routes:

php artisan route:clear
php artisan route:cache
Easton answered 19/8 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.