简体   繁体   中英

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.

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM