API url not found on server error - php

I have deployed an API built using lumen 5.4 on shared hosting. I'm able to hit the the main domain elomena.xyz but cannot access elomena.xyz/users
Local server test with postman is successful but I get this error when i try to reach it from production environment
Not Found
The requested URL /users was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This is the content of my web.php file
$app->get('/', function () use ($app) {
return $app->version();
});
// Users
$app->get('/users', 'UserController#index');
$app->post('/users', 'UserController#store');
$app->get('/users/{user_id}', 'UserController#show');
$app->put('/users/{user_id}', 'UserController#update');
$app->delete('/users/{user_id}', 'UserController#destroy');
// Orders
$app->get('/orders', 'OrderController#index');
$app->post('/orders', 'OrderController#store');
$app->get('/orders/{order_id}', 'OrderController#show');
$app->put('/orders/{order_id}', 'OrderController#update');
$app->delete('/orders/{order_id}', 'OrderController#destroy');
I can't find the reason why I can get to elomena.xyz but not elomena.xyz/users in production environment. I need help as i have been on this for over 48hrs already.

Related

Error 403 when receiving http post from another server

I'm implementing a payment method in PHP Laravel 5.6, and i'm supposed to receive an online notification through POST to an url i provide. It is getting Error 403, my POSTS from within the APP work completely fine.
As this POST comes from outside with no csrf, i've added my route on VerifyCSRF exceptions. but still it keeps saying 403.
I'm using Laravel 5.6 on AWS Elastic beanstalk on a load balancer, on top of this i use cloudflare.
web.php route
Route::post('/tpv/notificationOK', 'TPVController#order_notificationOK');
VerifyCsrfToken.php
protected $except = [
'tpv/notificationOK',
'https://www.pcmaker.es/tpv/notificationOK'
];
I expect to receive a POST and execute order_notificationOK function on /tpv/notificationOK URL but instead i'm getting "Server returned HTTP response code: 403 for URL: /tpv/notificationOK"
----------EDIT-------------
Just in case it can help someone, Cloudflare was blocking the POST request causing into an error 403, i just had to whitelist the ip where the POST came from and it works fine.

Laravel 5.4 Error 405 Method Not Allowed Error

I have Laravel 5.4 and VueJs application. When I run it in Localhost it was worked but now. I host in a server it gives the error GET > 405 Method Not Allowed Error. But GET requests are work fine. But this function I'm not using GET request. I using POST. But I giving this error. I have Installed CORS also. What can I do?
This is my POST Request in VueJS
this.$http.post("api/sendbooking",this.booking)
.then(function (response){
console.log(response)
})
This is api.php
Route::post('/sendbooking',[
'uses' => 'BookingController#setBooking'
]);
You're attempting to make a request that is unauthorized or otherwise not configured correctly. 405 means unauthorized HTTP verb in the request. Double check your route files that you can POST to the route you want to reach.
Anytime I see this is when I accidentally try to use GET on a POST route or similar.
And since you mentioned CORS, make sure all the required verbs are listed as allowed.

POST call to Lumen API not working on production server

I have this strange issue where making a POST request to my production server results in the response I have defined for the GET request to the same route. POST works fine for my local development server. Here's the code I'm using:
routes/web.php:
$router->get('/', function () use ($router) {
return "Lumen is running.";
});
$router->group(['prefix' => 'v1'], function($router)
{
$router->get('message','MessageController#index');
$router->post('message','MessageController#create');
});
So, when I send a POST request to productionurl.com/v1/message, create() isn't executed, but when I send the exact same request to developmenturl.com/v1/message, it is.
I've tried deleting all routes but the POST one, this results in a MethodNotAllowedHttpException on the production server.
I've setup PHP7.0, Nginx and MongoDB manually on a Ubuntu 16.04 VPS.
Development server is a Homestead VM with PHP7.1 and Nginx, with MongoDB running on my host computer.

lumen http error 500 in nginx and how to see error_log?

my php project with lumen is ok on my computer with WAMP (windows.apache.mysql.php) environment.
but when i upload it to my server on with LNMP (Linux,nginx,mysql,php) environment,
i enter the URL , it came to HTTP ERROR 500
the root is
/home/wwwroot/www.projectname.cn/projectname/public;
So i put a test.php at "/home/wwwroot/www.projectname.cn/projectname/public"
enter www.projectname.cn/test.php
it's the right page.
so i change the index.php
<?php
$app = require __DIR__.'/../bootstrap/app.php';
dump($app);
//$app->run();
also is HTTP ERROR 500
and at local environment , i add a route in projectname/app/Http/routes.php
<?php
$app->get('/', function() use ($app) {
return $app->welcome();
});
$app->get('/hello', function() {
return "hello ";
});
i enter “www.projectname.cn/hello” it also doesn't work
the routes.php doesn't work
what's maybe the reason caused that ??
You can see the error log dynamically using the command
tail -f /var/log/nginx/error.log
This is the default nginx configuration in Debian/Ubuntu, so you could have to change error.log route.

500 Internal server error in Laravel for every route

My laravel application was working very fine, until I installed entrust.
Now, all my routes which are grouped gives me 500 server error. However, the route when placed out of group gives me the desired result.
Route::get('ticker', 'UsersController#index');
This gives me perfect result.
However, this doesn't.
Route::group(['prefix' => 'api/v1'], function() {
Route::get('ticker', 'UsersController#index');
});
What has gone wrong? I am unable to figure out. I also tried logging errors in apache, but doesn't give me a error in the log file.

Categories