简体   繁体   中英

PHP: when going to end point it is not found locally but found remotely

sorry for this question I am extremely new to PHP/Laravel ( I am a Node user and have to dig through this legacy code). I have a server running locally but whenever I use Postman to check some of the endpoints I keep getting a response of 500 Server error. I ran the command $ php artisan serve --port=8000 and get the response back:

Laravel development server started: http://127.0.0.1:8000

now whenever I try and send any request [localhost:8000/getTowns] to the server I get a 500 error and in the terminal there is no stack trace or errors being shown it is completely empty.

Now when I launch the server with the command $ php -S localhost:8000 I get:

PHP 7.1.23 Development Server started at Wed Nov 13 12:55:52 2019

Listening on http://localhost:8000

Document root is /Users/user/Desktop/legacy

Press Ctrl-C to quit.

then when making any request I get

[Wed Nov 13 12:56:06 2019] ::1:59504 [404]: /getTowns - No such file or directory
[Wed Nov 13 12:56:07 2019] ::1:59505 [404]: /favicon.ico - No such file or directory

I don't know whatever information is relevant for this, but, I will update with more relevent code when requested. Thanks!

update: Looking in the logs, I see a lot of:

laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [] is not defined.

laravel.ERROR: Unable to prepare route [/] for serialization. Uses Closure. {"exception":"[object] (LogicException(code: 0): Unable to prepare route [/] for serialization. Uses Closure. 

Might be a silly thing or a typo in the question, but the message posted says that the laravel dev server runs on port 3000. The requests you are making are on port 8000. If your ports are in fact correct (aka, the default 8000, for example), my best guess is that you haven't run composer install in the project root folder ('legacy').

For the php native server, you are starting it in your 'legacy' folder where the project is located. Laravel projects should have their webroot in the 'public' folder of the project (aka 'legacy/public' - I would assume, in your case).


EDIT: as per being unable to run composer install successfully:

the issue is a route that may look like this:

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

this route uses a Closure, which can't be serialized. You should update it so that it uses a Controller method.

Something like

Route::get('/some/route', 'UserController@getIndex');

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM