slim\exception\httpnotfoundexception grocy
uncaught slim exception httpnotfoundexception not found routingmiddleware
slim framework
slim 4
slim 4 tutorial
slim framework tutorial
appfactory slim
slim routes

I'm creating a new Slim project and getting the following error: Slim Application Error: The application could not run because of the following error:

Error Details

Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php
Line: 91


#0 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php(57): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\MiddlewareDispatcher.php(124): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner))
#2 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\Middleware\ErrorMiddleware.php(89): class@anonymous->handle(Object(Slim\Psr7\Request))
#3 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\MiddlewareDispatcher.php(124): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(class@anonymous))
#4 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\MiddlewareDispatcher.php(65): class@anonymous->handle(Object(Slim\Psr7\Request))
#5 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\App.php(174): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#6 C:\xampp\htdocs\MyApi\vendor\slim\slim\Slim\App.php(158): Slim\App->handle(Object(Slim\Psr7\Request))
#7 C:\xampp\htdocs\MyApi\public\index.php(18): Slim\App->run()
#8 {main}

Here is my index.php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require '../vendor/autoload.php';

$app = AppFactory::create();
$errorMiddleware = $app->addErrorMiddleware(true, true, true);

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;


This might be a basic problem.But I am new.Need help please.

To solve the problem with Slim 4 here is what I did :

1/ Just after

$app = AppFactory::create();

I added :

$app->setBasePath("/myapp/api"); // /myapp/api is the api folder (http://domain/myapp/api)

2/ In my .htaccess :

RewriteEngine on  
RewriteCond %{ENV:REDIRECT_STATUS} !200 RewriteRule
^api/(.*)$ api/index.php/$1

3/ Finaly to handle the 'HttpNotFoundException' Slim Exception I added a try/catch (I don't know why Slim doesn't handle it internaly => maybe to give us more possibility?)

try {
} catch (Exception $e) {    
  // We display a error message
  die( json_encode(array("status" => "failed", "message" => "This action is not allowed"))); 

Hope it can help

** Edited => To force Slim to handle Exceptions, after : **

$app = AppFactory::create();

add :

$app->addErrorMiddleware(true, true, true);

Ref :

HttpNotFoundException not found, Hello, there was such an error “HttpNotFoundException not found” brief description: Type: Slim\Exception\HttpNotFoundException Code: 404� ) Slim\Exception\HttpNotFoundException: Not found. in C:\xampp\htdocs\www\myslimsite\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php on line 91 What’s the problem here? How can I get it installed without errors?

I was getting the same error, let me describe what I was exactly doing and then how did it work! I was running local server using the command on terminal php -S localhost:8002 The command returned Document root is /Users/Codeus/Desktop/ and error occured when I navigated to localhost:8002 Then again I ran localhost from the directory where index.php or whatever your is that you wanna run and it worked fine for me. For example, for me, it was two levels up then command php -S localhost:8002 returned Document root is /Users/Codeus/Desktop/myslim/src/public and this is exactly where my index.php file was. Hope this works for you as well.

Installation error: (HttpNotFoundException), Hello, I followed the Slim installation instructions and here is what I get on Fatal error: Uncaught Slim\Exception\HttpNotFoundException: Not� Help with Page not found not work Slim Exception HttpNotFoundException. mack_sho November 29, 2019, 3:08am #19. Thanks, this is helpful it worked for me after hours

Open CMD in your Project Root - Type

composer require slim/slim:3.*

Then It Will Update then refresh the browser that's it.

Application, The Application Slim\App is the entry point to your Slim application and is used to register the routes that link use Slim\Exception\HttpNotFoundException; use� The Application Slim\App is the entry point to your Slim application and is used to register the routes that link to your callbacks or controllers.

This worked for me (based on Mandien's answer).

I've just added index.php in setBasePath(...), no .htaccess needed.


// Define app routes
$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;


shows Hello, world

Linux, Apache, Slim 4

Slim\Exception\HttpNotFoundException, To solve the problem with Slim 4 here is what I did : 1/ Just after $app = AppFactory::create();. I added : $app->setBasePath("/myapp/api");� Slim is a powerful php micro framework which allows developers to create web applications. In this tutorial I am going to describe you about how to install Slim Framework 3.

404 Not Found, 404 Not Found - Slim\Exception\HttpNotFoundException. Hello, I am making a plugin for the home automation system. I'm looking to install grocy from the plugin . @l0gicgate Version 3 has a Tutorial link with a guide to creating a "first application". Slim 4 with all the decoupling and plug-in choices (PSR-7, Containers, Route & ErrorHandling as middleware, etc.) is much more complex than Slim 3.

404 Not Found, 404 Not Found - Slim\Exception\HttpNotFoundException #661. Closed. Hotfirenet opened this issue on Mar 25 � 5 comments. Closed� Table of contents. Of course this example is very limited in its functionality. To catch all http errors you could use the HttpException within the catch block.. If you want to log all http errors or render Twig templates then you should implement a custom Slim DefaultErrorHandler or a HttpExceptionMiddleware.

Slim 4, Uncaught Slim\Exception\HttpNotFoundException: Not found. We are trying to make our custom error in the JSON format, for example:. I’m closing this as resolved. The docs are clear. If you dislike the architecture you can always use a different framework. You’re also more than welcome to contribute when those architecture decisions are being made, the PRs and discussions are public.

System Error Handler, Each Slim Framework application has an error handler that receives all uncaught PHP exceptions. This error handler also receives the current HTTP request� Obrigado por contribuir com o Stack Overflow em Português! Certifique-se de responder à pergunta.Entre em detalhes sobre a sua solução e compartilhe o que você descobriu.

  • What url are you trying to visit? What code did you add to the slim app?
  • The information you provided is not enough to identify the problem. Please consider adding more details to your question. Most importantly, the URL you're trying to visit and routes definitions in your code.
  • Please provide the directory that your index.php is in and the URL that you are using that gives the error.
  • Clearly not resolving the v4 trouble. See this answer on the Slim forum