# Slim Framework 4 with php 8.1 and IIS Server comunication

**URL:** https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068
**Category:** Questions
**Created:** [March 6, 2025, 11:50am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068 "2025-03-06T11:50:49Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [March 6, 2025, 11:50am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/1 "2025-03-06T11:50:49Z")

</div>

I have a problem with the operation of the website.

I installed slim framework v.4 I have php v.8.1 and the server IIS [Slim 4 Documentation - Slim Framework](https://www.slimframework.com/docs/v4/) I used this code to try if the project would start and unfortunately after many different attempts I was unable to start the website correctly.

I searched the forums but it still does not work. Has anyone encountered this problem before on the IIS server?

I believe that the cause may be this server and it will have to be configured accordingly, please advise.

I used url: `http://localhost/TestSlim/index.php/`. I am trying different paths without index.php : `http://localhost/TestSlim/` or `http://localhost/TestSlim/index.php/hello` few times I reinstaled slim but without success. I am not sure how it works with IIS.

I used different methods I saw that problem isn’t exist for php 7.3.3 but higher like 8.1 is a problem with that

This is my index.php:

> \<?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require \_\_DIR\_\_ . '/vendor/autoload.php'; //echo "test"; $app = AppFactory::create(); $app-\>addRoutingMiddleware(); $errorMiddleware = $app-\>addErrorMiddleware(true, true, true); $app-\>setBasePath('localhost/TestSlim'); echo $app-\>getBasePath(); $app-\>get('/', 'hello'); // Run app $app-\>run(); ?\>

And I see the following error:

> 404 Not Found Type: Slim\Exception\HttpNotFoundException Code: 404 Message: Not found. File: C:\TestSlimFramework\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php Line: 91 Trace: #0 C:\TestSlimFramework\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php(58): Slim\Middleware\RoutingMiddleware-\>performRouting(Object(Slim\Psr7\Request)) #1 C:\TestSlimFramework\vendor\slim\slim\Slim\MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware-\>process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner)) #2 C:\TestSlimFramework\vendor\slim\slim\Slim\Middleware\ErrorMiddleware.php(107): Psr\Http\Server\RequestHandlerInterface@anonymous-\>handle(Object(Slim\Psr7\Request)) #3 C:\TestSlimFramework\vendor\slim\slim\Slim\MiddlewareDispatcher.php(147): Slim\Middleware\ErrorMiddleware-\>process(Object(Slim\Psr7\Request), Object(Psr\Http\Server\RequestHandlerInterface@anonymous)) #4 C:\TestSlimFramework\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): Psr\Http\Server\RequestHandlerInterface@anonymous-\>handle(Object(Slim\Psr7\Request)) #5 C:\TestSlimFramework\vendor\slim\slim\Slim\App.php(215): Slim\MiddlewareDispatcher-\>handle(Object(Slim\Psr7\Request)) #6 C:\TestSlimFramework\vendor\slim\slim\Slim\App.php(199): Slim\App-\>handle(Object(Slim\Psr7\Request)) #7 C:\TestSlimFramework\index.php(23): Slim\App-\>run() #8 {main}

I already deployed on IIS using Server-\>Sites-\>Default Web Site-\>Add Virtual Directory:

and added simple structure from directory

---

<div class="post-metadata">

### Author: ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)
#### Post date: [March 6, 2025, 12:25pm UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/2 "2025-03-06T12:25:10Z")

</div>

For IIS you need the `Web.config` file and `index.php` files are in the same public-accessible directory. The `Web.config` file should contain this code:

> **[Web Servers](https://www.slimframework.com/docs/v4/start/web-servers.html#iis)**

---

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [March 7, 2025, 9:49am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/3 "2025-03-07T09:49:10Z")

</div>

Hello I already did that:

 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/8/83e86ddbb7b70f2379a62b2ffd5df67876f01ce4.png)  
this is code in config:  
 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/d/daedc5260cc5b0d91eba190c298d0089ed55baee.png)  
this is code index.php:  
 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/c/c68464998e0f04140d65ac1aa7467f2b387e2208.png)

I retstarted IIS and still the same issue

---

<div class="post-metadata">

### Author: ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)
#### Post date: [March 7, 2025, 12:13pm UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/4 "2025-03-07T12:13:19Z")

</div>

This looks like a typical basePath issue. Is your site running in a sub-directory of the IIS document root?

Try to comment out this line or install the basePath middleware instead:

> $app-\>setBasePath(‘TestSlimFramework’);

- [GitHub - selective-php/basepath: Base path detector for Slim 4](https://github.com/selective-php/basepath?tab=readme-ov-file#installation)

Remove this line because it causes response buffer issues:

> echo $app-\>getBasePath();

The handler should be a valid. Change this line

> $app-\>get(‘/’, ‘hello’);

to

```php
$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write('Hello World');
    
    return $response;
});

```

---

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [March 10, 2025, 8:46am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/5 "2025-03-10T08:46:10Z")

</div>

Thank you for respond I made a change:

 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/b/be1f6224f99a7b43c8195ca36844bd89d259c1a2.png)  
Still the same issue

---

<div class="post-metadata">

### Author: ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)
#### Post date: [March 10, 2025, 5:04pm UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/7 "2025-03-10T17:04:38Z")

</div>

> $app-\>setBasePath(‘TestSlimFramework’);

The basePath, if any, should start with a “/”. I would try to commend out this line or use the basePath from your URI path. Otherwise try to install the BasePath middleware for auto-detection.

---

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [March 18, 2025, 12:35pm UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/8 "2025-03-18T12:35:02Z")

</div>

Yeah I founded solution I did:  
$app-\>setBasePath(‘/TestSlim’); the same directory as on IIS  
and Web.config:

> \<?xml version="1.0" encoding="UTF-8"?\>

This is work for me. Thank you

---

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [April 9, 2025, 7:52am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/9 "2025-04-09T07:52:02Z")

</div>

I want to continue this issue because on the same configuration I was trying to use method DELETE and PUT. Not works form me only POST and GET.

```auto
$app->delete('api/hello/remove/{id}', function ($request, $response, $args) {
  $id = $args['id'];
  $response->getBody()->write("Item with ID $id has been deleted.");
  return $response->withStatus(200);
});

$app->put('api/hello/put/{id}', function ($request, $response, $args) {
  $id = $args['id'];
  $response->getBody()->write("Item with ID $id has been deleted.");
  return $response->withStatus(200);
});

```

I was trying to add some allows for DELETE and PUT in IIS configurations but nothing happened still the same issue. Full code below:

```auto
<?php 
    use Psr\Http\Message\ResponseInterface as Response;
    use Psr\Http\Message\ServerRequestInterface as Request;
    use Slim\Factory\AppFactory;
    use Slim\Middleware\MethodOverrideMiddleware;
    
    require __DIR__. '/vendor/autoload.php';

  //echo "test";
    $app = AppFactory::create();
    $app->setBasePath('/TestSlim');
   
    $app->addBodyParsingMiddleware();
    $app->addRoutingMiddleware();
    $methodOverrideMiddleware = new MethodOverrideMiddleware();
$app->add($methodOverrideMiddleware);

    $errorMiddleware = $app->addErrorMiddleware(true, true, true);
    
    //$app->setBasePath('localhost/TestSlim');
    //echo $app->getBasePath();
    $app->get('/api/', function (Request $request, Response $response) {
      $response->getBody()->write("Welcome to Slim 4 on IIS!");
      return $response;
  });
  // Hello Route
  $app->get('/api/hello', function (Request $request, Response $response) {
      $response->getBody()->write("Hello, Slim!");
      return $response;
  });

  $app->post('/api/hello', function (Request $request, Response $response) {
    $response->getBody()->write("Hello, Slim!");
    return $response;
});
$app->add(function ($request, $handler) {
  return $handler->handle($request);
});

$app->delete('api/hello/remove/{id}', function ($request, $response, $args) {
  $id = $args['id'];
  $response->getBody()->write("Item with ID $id has been deleted.");
  return $response->withStatus(200);
});

$app->put('api/hello/put/{id}', function ($request, $response, $args) {
  $id = $args['id'];
  $response->getBody()->write("Item with ID $id has been deleted.");
  return $response->withStatus(200);
});

   
    
    // Run app
    $app->run();

?>

```

---

<div class="post-metadata">

### Author: ![LLEGAZ](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llegaz/32/1665_2.png) [@LLEGAZ](https://discourse.slimframework.com/u/LLEGAZ)
#### Post date: [April 11, 2025, 9:48am UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/10 "2025-04-11T09:48:40Z")

</div>

Try the `RouteCollectorProxy`

---

<div class="post-metadata">

### Author: ![PeterW](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@PeterW](https://discourse.slimframework.com/u/PeterW)
#### Post date: [April 23, 2025, 1:26pm UTC](https://discourse.slimframework.com/t/slim-framework-4-with-php-8-1-and-iis-server-comunication/6068/11 "2025-04-23T13:26:07Z")

</div>

I was trying using RouteCollectorProxy this way:

> $app-\>group(‘/api’, function (\Slim\Routing\RouteCollectorProxy $group) {  
> $group-\>delete(‘/item/{id}’, function ($request, $response, $args) {  
> $id = $args[‘id’];  
> // Perform delete logic here (e.g., delete item from DB)
> 
> ```
> $response->getBody()->write("Item with ID $id has been deleted.");
> return $response;
> 
> ```
> 
> });  
> });

Nothing happened trying to using postman and get this error:  
 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/7/73fc262ec1736b77fd6917bcbabb23457548cb67.png)  
This kind of 405 error is when I am trying to use RouteCollectorProxy and without.  
I was trying to add to IIS:

 ![obraz](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/f/f717ab7c84d16e7612b6a64266f6d88d1e902e1c.png)  
But without effect I saw the same issue
