-1

Error Image here

Login Route

Route::get('/', [HomeController::class, 'index'])
    ->name('index')
    ->breadcrumbs(function (Trail $trail) {
        $trail->push(__('Home'), route('frontend.index'));
    });

Authentication Routes

Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('login', [LoginController::class, 'login']);

Problem:

My project is working fine when I run it locally but when I upload it on the server it shows Method Not Allowed exception. I don't know why. When I used to run URL like www.domain.com/billingsystem/ it gives the above error but when I run URL like www.domain.com/billingsystem/index.php or www.domain.com/billingsystem/public it runs fine on the server. I am actually not finding the solution for this anyone please help me regarding this.

Thanks and Regards.

Kartik Agarwal
  • 1,129
  • 1
  • 8
  • 27

1 Answers1

0

This has to do with your web server configuration. Laravel uses the index.php file as the entry point for all its requests. So you have to tell all your sub routes to be passed through this file. The configuration depends on the web server you are using. I'll show you how you can fix it using nginx and apache2.

nginx

Open the configuration file (usually found in /etc/nginx/sites-avialable/default) and under the location section, edit the line:

try_files $uri $uri/ =404;

to

try_files $uri $uri/ $uri/index.php =404;

Save the file and restart nginx using sudo service nginx restart.

apache2

For apache2 you need a properly setup .htaccess file under your /public directory of your project. By default Laravel ships with one. You just need to tell apache2 to read that file and respect the rules.

First enable mod_rewrite by running:

sudo a2enmod rewrite

Then go to your apache2 configuration file located at /etc/apache2/apache2.conf and find the section that says <Directory /var/www/html> (or the path to your Laravel project public folder) and add/edit the line below:

AllowOverride All

Restart apache2 using sudo service apache2 restart.

tamrat
  • 1,815
  • 13
  • 19