Search code examples
phplaravelapachemanjaro

My routes return errors in Laravel, Apache


Whenever I try to use a route I get "object not found" and "error 404". I am running my server on Manjaro/Arch (locally anyway). Also, this is my first time using Laravel.

I am using Apache for my server. It is running as I can load the Laravel page from 127.0.0.1/path/to/public/. I have been using this same server for other projects and have had no issues.

I even tried changing the document root to the actual root, i.e., I can now just run using 127.0.0.1

I have changed Allow override to All in my httpd.conf which seems to solve this issue for 99% of people. I made sure I restarted the server after .conf edits.

my web.php: (that first route is the only code I have written for this project)

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

Route::get('/', function () {
    return view('welcome');
});

output from command php artisan route:list

+--------+----------+----------+------+---------+--------------+
| Domain | Method   | URI      | Name | Action  | Middleware   |
+--------+----------+----------+------+---------+--------------+
|        | GET|HEAD | /        |      | Closure | web          |
|        | GET|HEAD | api/user |      | Closure | api,auth:api |
|        | GET|HEAD | hello    |      | Closure | web          |
+--------+----------+----------+------+---------+--------------+

From what other solutions to this question I have seen suggest that my .htaccess is correct:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

This, not a Laravel issue I think as if I run php artisan serve I can use the route finding, i.e., 127.0.0.1:8000/hello will print hello world in my browser.


Solution

  • Had to add:

    LoadModule rewrite_module modules/mod_rewrite.so
    

    to the end of my httpd.conf file

    [edit]

    Also had to give permission to some files for some reason. (log files).