Laravel artisan serve on remote server

2.2k Views Asked by At

Hi I have deployed my Laravel app on a remote server using sudo php artisan serve --host 0.0.0.0 --port 80 but when I login I get TokenMismatchException. The app is working fine in my local environment and my login form did contains {{ csrf_field() }}

2

There are 2 best solutions below

1
On

Try this:

I'm assuming you added $this->middleware('auth'); inside the constructor of your controller to get the authentication working. Add the following at the top as well, under your login/register forms, if you are using {!! Form::someElement !!}:

{!! csrf_field() !!}

Or if you are using input tags inside your forms, just add this just after the tag:

<input type="hidden" name="_token" value="{{ csrf_token() }}">

TokenMismatchException in VerifyCsrfToken.php Line 67

1
On

First of all, you should not use php artisan serve command in the production mode. You have to just point out the baseUrl like http://or.net/ to laravel's public/index.php file. It will bootstrap your laravel application with all the dependencies. For more details on the hosting of laravel on shared server, visit this CW answer.

And the solution to the CSRF token problem is answered by @sujalPatel. You have to add

{!! csrf_field() !!} not {{ csrf_field() }}