# Error in hello world

**URL:** <https://discourse.slimframework.com/t/error-in-hello-world/3360>\
**Category:** Questions\
**Created:** [August 16, 2019, 9:07am UTC](https://discourse.slimframework.com/t/error-in-hello-world/3360 "2019-08-16T09:07:30Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [August 20, 2019, 9:09pm UTC](https://discourse.slimframework.com/t/error-in-hello-world/3360/8 "2019-08-20T21:09:48Z")

</div>

The last days I played with Slim 4 and tried to find a more “elegant” solution for apache users running a Slim 4 app in a documentRoot `public/` or a sub-directory of documentRoot.

Then I discovered `$app->setBasePath($basePath)`. You can pass a fix value or let a function (library) detect the real basePath for you.

**Example** :

```php
$app = AppFactory::create();

// Set the base path to run the app in a subdirectory.
// This path is used in urlFor().
$basePath = (new BasePathDetector($_SERVER))->getBasePath();
$app->setBasePath($basePath);

```

**Edit** : Here you can find the library: [selective-php/basepath](https://github.com/selective-php/basepath)

---

_[View the full topic](https://discourse.slimframework.com/t/error-in-hello-world/3360)._
