Saturday, October 30, 2021

[SOLVED] How to fix Laravel Error 404 in acceptance environment?

Issue

I try to install my Laravel application in a new environment acceptance,

After composer install (no errors)

when I check the url it's redirected to /login which is normal

The problem: it returns 404 error and this error is coming from the server not from Laravel because I customized 404 error in my application

enter image description here

it seems like the server does accept only / path :

also when I change the router :

from

Route::get('/', function () {
    if (Auth::check()) return redirect('/myprofile');
    return redirect('/login');
});

To this:

Route::get('/', function () {
    return 'hello world'
});

it works and I can see hello world

the route /login exists when I route:list


Solution

First check if Apache's mod_rewrite module is enabled, If it's not enabled aleady please run below commands to enable it or else jump to second part of the answer

sudo a2enmod rewrite
sudo service apache2 restart

Also add below config block in your virtual host configuration to enable laravels .htaccess rules

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Change /var/www/ path accordingly



Answered By - Vishal