Closed newbie14 closed 6 years ago
What is the error message?
I cant view any error message.I am non nginx both in the error log or access log I just error 500. Where else can I check for the error ?
Look at the error log. Where it is stored depends on your operating system and also PHP settings. For example in CentOS the default location is /var/log/httpd
. StackOverflow is a good place to find that information, for example see: "Where does PHP store the error log?".
Hi, I am running nginx I have checked the /var/log/nginx the error.log nothing is hinting to this.
Hi, Yes I am running the latest 3.x version. So what changes should I do more cause I notice I am using this. $app->add(new Tuupola\Middleware\JwtAuthentication([ "rules" => [ new Tuupola\Middleware\JwtAuthentication\RequestPathRule([ "path" => "/", "ignore" => [] ]), new Tuupola\Middleware\JwtAuthentication\RequestMethodRule([ "ignore" => ["OPTIONS"] ]) ] ])); I notice when I just use this $app->add(new Tuupola\Middleware\JwtAuthentication([ is not any issue but when I put the rules I notice I am getting error 500.
Look at the PHP error log to see hints what causes the 500 error. Not sure where it goes by default with nginx.
Hi, The problem is the error log not showing any indication for this. I am using nginx could that be the issue?
Nginx works fine, that is not the culprit. Google search for php error log nginx
reveals couple of alternative locations for the PHP error log and some other configuration settings which might be needed. For example:
https://stackoverflow.com/questions/8677493/php-fpm-doesnt-write-to-error-log https://serverfault.com/questions/417102/nginx-not-logging-php-errors
In general it is quite hard to write code if you do not have an error log :)
As a sidenote, you only need to pass the rules
parameter if the defaults are not ok for your use case.
Below is how my middleware codes looks like.
use Tuupola\Middleware\HttpBasicAuthentication;
$container = $app->getContainer(); $container['logger'] = function($c) { $logger = new \Monolog\Logger('my_logger'); $file_handler = new \Monolog\Handler\StreamHandler("../logs/app.log"); $logger->pushHandler($file_handler); return $logger; };
$container["jwt"] = function ($container) { return new StdClass; };
$app->add(new \Slim\Middleware\JwtAuthentication([ "path" => "/", "logger" => $container['logger'], "secret" => "123456789helo_secret", "rules" => [ new \Slim\Middleware\JwtAuthentication\RequestPathRule([ "path" => "/", "passthrough" => ["/login"] ]), new \Slim\Middleware\JwtAuthentication\RequestMethodRule([ "passthrough" => ["OPTIONS"] ]), ], "callback" => function ($request, $response, $arguments) use ($container) { $container["jwt"] = $arguments["decoded"]; }, "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)); } ]));
The moment I added this code block $app->add(new \Slim\Middleware\JwtAuthentication([ I get error 500. Here is how my composer.json looks like
{ "name": "slim/slim-skeleton", "description": "A Slim Framework skeleton application for rapid development", "keywords": ["microframework", "rest", "router", "psr7"], "homepage": "http://github.com/slimphp/Slim-Skeleton", "license": "MIT", "authors": [ { "name": "Josh Lockhart", "email": "info@joshlockhart.com", "homepage": "http://www.joshlockhart.com/" } ], "require": { "php": ">=5.5.0", "slim/slim": "^3.1", "slim/php-view": "^2.0", "monolog/monolog": "^1.17", "tuupola/slim-jwt-auth": "^3.0", "tuupola/cors-middleware": "^0.7.0", "tuupola/slim-basic-auth": "^3.1" }, "require-dev": { "phpunit/phpunit": ">=4.8 < 6.0" }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } }, "config": { "process-timeout" : 0 }, "scripts": { "start": "php -S localhost:8080 -t public", "test": "phpunit" }
} After running the composer to install slim/slim-skeleton . Then I just cd into the api folder and ran this commands.
composer require tuupola/slim-basic-auth composer require tuupola/cors-middleware composer require tuupola/slim-jwt-auth
Is there any thing else I missed here ?