Search code examples
laravel.htaccess

Why does this Laravel 8 API throw an Internal Server Error?


I am working with a Laravel 8 API, that I cloned.

It works on a live server but on my local WAMP server it throws a 500 Internal Server Error.

The apache_error.log shows:

Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

The content of the .htaccess file, placed in the public directory (where the virtual host points) is:

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

    RewriteEngine On

    Header always set Access-Control-Allow-Origin "*"
    Header always set Access-Control-Max-Age "1000"
    Header always set Access-Control-Allow-Headers "Accept, Accept-Encoding, Authorization, Content-Type, Origin, X-Requested-With"
    Header always set Access-Control-Allow-Methods "GET, DELETE, PATCH, POST, PUT, OPTIONS"

    # 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>

NOTE:

Other PHP / Laravel applications do work on the local environment.

Also, mod_rewrite is enabled.

What is causing the issue?


Solution

  • "...or defined by a module not included in the server configuration" suggests that you need to enable a module first. Header is part of mod_headers in Apache.

    Enable that module in your WAMP to make Header work.

    Go to wamp64\bin\apache\apache2.4.46\conf, open httpd.conf find LoadModule headers_module modules/mod_headers.so and uncoment it.

    Then restart WAMP.