jerome
jerome

Reputation: 1

Laravel 11 Filament Admin Issues in Production: 405, 403 Errors, and JavaScript Not Functioning

Important infirmation : this problem dont appear in local, but only in remote

I’m encountering several issues with my Laravel 11 application in production. Everything works perfectly in my local environment, but once deployed to my production server (OVH shared hosting), I face the following problems:

Issues

  1. 405 Method Not Allowed When I submit the login form on the Filament Admin panel (POST /admin/login), I get the following error:

sql The POST method is not supported for route admin/login. Supported methods: GET, HEAD. This issue does not occur locally. The POST request works fine when testing on my local environment.

  1. JavaScript Not Working On the Filament Admin login page, the "show/hide password" button does not work, suggesting that JavaScript assets might not be loading or executing correctly in production.

  2. 403 Forbidden After logging into my application and trying to access /admin using a button in the app, I get a 403 Forbidden error.

Additional Information Laravel version: 11.33.2 PHP version: 8.2.21 Server: OVH shared hosting SSL: Enabled (Let's Encrypt) Environment: APP_ENV=production APP_DEBUG=false Configuration & Setup I’m using Filament Admin and deployed the app with composer install --no-dev --optimize-autoloader. The public directory is split: The public/build directory (for assets) is in www/nomadcalc/build. All other files from public are directly in www/.

Steps Taken Cleared caches:

bash Copier le code php artisan config:clear php artisan route:clear php artisan cache:clear No success; the issue persists.

Verified .htaccess: My .htaccess file is configured to redirect all traffic to HTTPS and handle Laravel routing correctly.

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteCond %{THE_REQUEST} !\s/index\.php
    RewriteRule ^ %1 [L,R=301]


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

Checked Middleware Configuration:

Middleware configuration in Laravel 11 has moved to bootstrap/app.php. My current setup is:

<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

Server Logs:

There are no specific errors in the logs indicating the cause of these issues. Debugging locally or with APP_DEBUG=true doesn’t reveal any additional information.

My Questions Why does the login route (POST /admin/login) return a 405 error in production but works locally? What could be causing JavaScript to fail for the "show/hide password" functionality? Why am I getting a 403 error when trying to access /admin after login? Any insights or suggestions would be greatly appreciated! Thank you in advance! 😊

Upvotes: 0

Views: 223

Answers (1)

imwill
imwill

Reputation: 598

I just ran into the same issue with 403 forbidden when deploying my Laravel app to production.

I found this in the docs:

Deploying to production

Allowing users to access a panel

By default, all User models can access Filament locally. However, when deploying to production, you must update your App\Models\User.php to implement the FilamentUser contract — ensuring that only the correct users can access your panel

[...]

If you don't complete these steps, a 403 Forbidden error will be returned when accessing the app in production.

Source: https://filamentphp.com/docs/3.x/panels/installation#allowing-users-to-access-a-panel

A simple fix without considering any security could be:

<?php
 
namespace App\Models;
 
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Foundation\Auth\User as Authenticatable;
 
class User extends Authenticatable implements FilamentUser
{
    // your user model code
 
    public function canAccessPanel(Panel $panel): bool
    {
        return true;
    }
}

Upvotes: 0

Related Questions