Leebo
Leebo

Reputation: 23

Laravel: How to decide using server.php or public/index.php

Laravel’ server.php and public/index.php are do the same thing, server.php is just require the public/index.php. So in my Apache http.conf file, I can use server.php or public/index.php in DirectoryIndex, and also can set the DocumentRoot to the project root folder or the project’s public folder. The question is which case should I use the right configuration, and how to use it.

Upvotes: 2

Views: 4829

Answers (2)

Cy Rossignol
Cy Rossignol

Reputation: 16867

The server.php file is used with the serve Artisan command to start a lightweight webserver using PHP's internal webserver:

$ php artisan serve --port=8000 
Laravel development server started: <http://localhost:8000>

...which is equivalent to running the following command from the project's root directory:

$ php -S localhost:8000 -t public/ ../server.php

This is intended for simple development and prototyping only when we may not have or need a separate webserver yet, and production webservers should always direct requests to the index.php file in the public/ directory.

Upvotes: 4

fubar
fubar

Reputation: 17398

The comment in the server.php file explains it's purpose -

This file allows us to emulate Apache's "mod_rewrite" functionality from the built-in PHP web server. This provides a convenient way to test a Laravel application without having installed a "real" web server software here.

So if you're using Apache, use public/index.php.

Upvotes: 3

Related Questions