简体   繁体   English

Laravel:如何决定使用server.php或public / index.php

[英]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. Laravel的server.php和public / index.php是做同样的事情,server.php只是需要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. 因此,在我的Apache http.conf文件中,我可以使用DirectoryIndex中的server.php或public / index.php,还可以将DocumentRoot设置为项目根文件夹或项目的公用文件夹。 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: server.php文件与serve Artisan命令一起使用,以使用PHP的内部网络服务器启动轻量级网络服务器:

$ 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. 仅当我们可能还没有或需要单独的Web服务器,并且生产Web服务器应始终将请求定向到public /目录中的index.php文件时,这才用于简单的开发和原型制作。

The comment in the server.php file explains it's purpose - server.php文件中的注释说明了它的用途-

This file allows us to emulate Apache's "mod_rewrite" functionality from the built-in PHP web server. 该文件使我们可以从内置PHP Web服务器模拟Apache的“ mod_rewrite”功能。 This provides a convenient way to test a Laravel application without having installed a "real" web server software here. 这提供了一种测试Laravel应用程序的便捷方法,而无需在此处安装“真实的” Web服务器软件。

So if you're using Apache, use public/index.php . 因此,如果您使用的是Apache,请使用public/index.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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