# Run a website with the slim application

**URL:** <https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896>\
**Category:** Questions\
**Created:** [May 4, 2024, 8:16am UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896 "2024-05-04T08:16:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![samclia](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@samclia](https://discourse.slimframework.com/u/samclia)\
**Post date:** [May 4, 2024, 8:16am UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/1 "2024-05-04T08:16:55Z")

</div>

Good morning,

English is not my first language, so, please, be indulgent with my faults.  
this is my project skeleton:  
 ![skelton-slim-secretariat-web](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/2X/9/9f52b679aa64a5fd61f821462e683aa57ebb3016.png)

I’m making a website with bootstrap and slim. The webpages are in Views.

- To launch index.php I run the internal server PHP with:

```php
php -S localhost:8082 -t public

```

- I have named the entry of the website “accueil.php” in Views. I have made a route ('/accueil) to require accueil.php. I don’t if it’s the best way, To run it, i open firefox with this URL: localhost:8082/accueil. This page works. But not the internet menu Bootstrap. So it’s not a good idea.

The public folder is become the reference. I tried to see:

```php
php -S localhost:8082 -t src/Views

```

Of course, the site works without css

How can I resolve this problem?  
Do I have to use apache?

Thanks and have a good day.

---

<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:** [May 4, 2024, 10:49am UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/2 "2024-05-04T10:49:13Z")

</div>

The public/ directory should be the only access point to your Slim website/application from the web. So you should never use internal directories like ‘src/Views’ as the document root for your web server.

> But not the internet menu Bootstrap. So it’s not a good idea.

Can you please explain this with more details?

---

<div class="post-metadata">

**Author:** ![samclia](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@samclia](https://discourse.slimframework.com/u/samclia)\
**Post date:** [May 4, 2024, 11:31am UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/3 "2024-05-04T11:31:20Z")

</div>

In “routeur.php”, i put:

```php
return function (App $app) {
    $app->get('/accueil', ControlleurAccueil::class . ':accueil'); //lancement de la page accueil.php
{

```

and in the function accueil,

```php
public function accueil(Request $request, Response $response) : Response{
        // Inclure le fichier accueil.php
        include ( __dir__. '/../Views/accueil.php');
    }

```

* * *

I’m thing it’ too complicated:

- I can bring together these two parts

```php
$app->get('/accueil', function (Request $request, Response $response, $args) {
    // Inclure le fichier accueil.php
    include ( __dir__. '/../Views/accueil.php');
});

```

- it’s not very good to use include, in this case. I perhaps use “render” instead, but I haven’t the syntax to use it with the Php files. Is php-view permit to create render?
- With Slim it’s preferable to make one route per page?
- can Php internal server resolve the problem of the views and index.php? Or do I have to use Apache?

---

<div class="post-metadata">

**Author:** ![samclia](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@samclia](https://discourse.slimframework.com/u/samclia)\
**Post date:** [May 4, 2024, 1:45pm UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/4 "2024-05-04T13:45:10Z")

</div>

For the Bootstrap menu, I think it needs routes with rendering functionality like buttons instead of URLs. That’s my assumption. Is it wrong?

---

<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:** [May 4, 2024, 1:59pm UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/5 "2024-05-04T13:59:56Z")

</div>

Instead of the `include` function, you can use the [slim/php-view](https://github.com/slimphp/PHP-View) package, which allows you to render the PHP template directly into the Response object.

Simple example:

Run: `composer require slim/php-view`

```php
use Slim\Views\PhpRenderer;
// ...

$app->get('/accueil', function (Request $request, Response $response) {
    $renderer = new PhpRenderer( __DIR__. '/../Views');

    return $renderer->render($response, 'accueil.php');
});

```

> With Slim it’s preferable to make one route per page?

Yes

> Can PHP internal server resolve the problem of the views and index.php? Or do I have to use Apache?

The PHP internal server is just for development purposes. In production, you would use Apache for example. Generally, it works with any type of Webserver that runs PHP. Take a look at my example (see above).

> For the Bootstrap menu, I think it needs routes with rendering functionality like buttons instead of URLs. That’s my assumption. Is it wrong?

It depends. Usually the server returns a html page, that loads other resources such as JS and CSS files for Bootstrap and other website features.

---

<div class="post-metadata">

**Author:** ![samclia](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@samclia](https://discourse.slimframework.com/u/samclia)\
**Post date:** [May 4, 2024, 11:31pm UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/6 "2024-05-04T23:31:18Z")

</div>

Thanks, Odan.  
The website works with LAMP.  
I follow this page for the configuration: [Web Servers - Slim Framework](https://www.slimframework.com/docs/v4/start/web-servers.html)  
I create one route per page.  
For the bootstrap navbar, i use links like **href=“accueil”** (without/ . I found it with a mistake!)  
And for the button, I have to use the complete URL without .php like **[http://localhost/slim-secretariat-web/inscription](http://localhost/slim-secretariat-web/inscription)**  
Good night.

---

<div class="post-metadata">

**Author:** ![samclia](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@samclia](https://discourse.slimframework.com/u/samclia)\
**Post date:** [May 6, 2024, 1:53pm UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/7 "2024-05-06T13:53:20Z")

</div>

href=/slim-secretariat-web/inscription works also for the button.

---

<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:** [May 6, 2024, 6:02pm UTC](https://discourse.slimframework.com/t/run-a-website-with-the-slim-application/5896/8 "2024-05-06T18:02:19Z")

</div>

> href=/slim-secretariat-web/inscription works also for the button.

Ok. Just make sure that this path is the same in your production environment.
