tuupola / slim-api-skeleton

Slim 3 API skeleton project for Composer
MIT License
312 stars 62 forks source link

500 internal server error due to php_value always_populate_raw_post_data -1 #20

Closed Fshamri closed 7 years ago

Fshamri commented 7 years ago

I am getting 500 internal server error. my host support is saying it is because of

php_value always_populate_raw_post_data -1 in .httaccess file.

what does -1 means? how to fix this issue?

Thanks

tuupola commented 7 years ago

Have you tried removing that line?

Fshamri commented 7 years ago

I have commented it but get

"title": "Authentication failed", "type": "about:blank", "status": 401

tuupola commented 7 years ago

Show example curl request you are trying to do. That message tells the authentication failed, ie you are sending wrong credentials or not credentials at all.

Fshamri commented 7 years ago

curl "http://mobilepul.com/api/public/token" --request POST --include --header "Content-Type: application/json" --user test:test

tuupola commented 7 years ago

Have you configured basic auth to the route /api/public/token with credentials test and test?

Fshamri commented 7 years ago

this is from my middleware use App\Token; use Crell\ApiProblem\ApiProblem; use Gofabian\Negotiation\NegotiationMiddleware; use Micheh\Cache\CacheUtil; use Slim\Middleware\JwtAuthentication; use Slim\Middleware\HttpBasicAuthentication; use Tuupola\Middleware\Cors; $container = $app->getContainer(); $container["HttpBasicAuthentication"] = function ($container) { return new HttpBasicAuthentication([ "path" => "/token", "secure" => false,
"relaxed" => ["192.168.50.52"], "error" => function ($request, $response, $arguments) { $problem = new ApiProblem($arguments["message"], "about:blank"); $problem->setStatus(401); return $response ->withHeader("Content-type", "application/problem+json") ->write($problem->asJson(true)); }, "users" => [ "test" => "test" ] ]); }; $container["token"] = function ($container) { return new Token; }; $container["JwtAuthentication"] = function ($container) { return new JwtAuthentication([ "path" => "/", "secure" => false, "passthrough" => ["/token", "/info"], "secret" => getenv("JWT_SECRET"), "logger" => $container["logger"], "relaxed" => ["192.168.50.52"], "error" => function ($request, $response, $arguments) { $problem = new ApiProblem($arguments["message"], "about:blank"); $problem->setStatus(401); return $response ->withHeader("Content-type", "application/problem+json") ->write($problem->asJson(true)); }, "callback" => function ($request, $response, $arguments) use ($container) { $container["token"]->hydrate($arguments["decoded"]); } ]); }; $container["Cors"] = function ($container) { return new Cors([ "logger" => $container["logger"], "origin" => ["*"], "methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"], "headers.allow" => ["Authorization", "If-Match", "If-Unmodified-Since"], "headers.expose" => ["Authorization", "Etag"], "credentials" => true, "cache" => 60, "error" => function ($request, $response, $arguments) { $data["status"] = "error"; $data["message"] = $arguments["message"]; return $response ->withHeader("Content-Type", "application/json") ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); } ]); }; $container["Negotiation"] = function ($container) { return new NegotiationMiddleware([ "accept" => ["application/json"] ]); }; $app->add("HttpBasicAuthentication"); $app->add("JwtAuthentication"); $app->add("Cors"); $app->add("Negotiation"); $container["cache"] = function ($container) { return new CacheUtil; };

tuupola commented 7 years ago

You have configured basic auth to path /token but are requesting /api/public/token. See Basic Auth middleware documentation on how to configure it.

Fshamri commented 7 years ago

if my curl is like: curl "http://mobilepul.com/token" --request POST --include --header "Content-Type: application/json" --user test:test

OR curl "http://mobilepul.com/api/token" i get 404 NOT FOUND.

i think .htaccess file needs some modification

here is my .htaccess file content: RewriteEngine On

RewriteBase /api/

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

RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]

Make sure $HTTP_RAW_POST_DATA is deprecated warning does not appear

php_value always_populate_raw_post_data -1

tuupola commented 7 years ago

Things related to configuring Apache and Slim are better off asked in StackOverflow or Slim support forums. You probably have more luck finding answer there. GitHub issues are more meant for reporting bugs.