Laravel 4 中 server.php 文件的用途是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16919920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:53:13  来源:igfitidea点击:

What is the purpose of the server.php file in Laravel 4?

phplaravellaravel-4

提问by Michael Irigoyen

In the /app/directory in Laravel 4, there is a file called server.php. The contents of this file look like this:

/app/Laravel 4的目录中,有一个名为server.php. 该文件的内容如下所示:

<?php

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

$uri = urldecode($uri);

$paths = require __DIR__.'/bootstrap/paths.php';

$requested = $paths['public'].$uri;

// 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.
if ($uri !== '/' and file_exists($requested))
{
    return false;
}

require_once $paths['public'].'/index.php';

It seems that this file is in someway used to mimic Apache's mod_rewritefunctionality, however I cannot find anything in the Laravel documentationthat mentions it or it's use.

似乎这个文件在某种程度上用于模仿 Apache 的mod_rewrite功能,但是我在Laravel 文档中找不到任何提到它或它的用途的内容。

I currently am trying to utilize Laravel on an IIS server that I do not manage. I do not have the ability to modify the URL rewrite module options on IIS (I will in the future), but would like to get started working with the framework now, if possible. This server.phpfile seems like it may be a stop-gap solution to do just that.

我目前正在尝试在我不管理的 IIS 服务器上使用 Laravel。我无法修改 IIS 上的 URL 重写模块选项(我将来会这样做),但如果可能的话,我想现在就开始使用该框架。这个server.php文件似乎是做到这一点的权宜之计。

Can anyone shed some light on the purpose of the server.phpfile and how to use/activate it if the purpose is really to emulate Apache's mod_rewritefunctionality?

server.php如果目的真的是为了模拟 Apache 的mod_rewrite功能,任何人都可以阐明文件的用途以及如何使用/激活它吗?

回答by tplaner

It is meant to be used with PHP's internal web serverwhich was introduced in PHP 5.4.

它旨在与PHP 5.4 中引入的 PHP内部 Web 服务器一起使用。

According to the PHP manual:

根据PHP手册:

This web server is designed for developmental purposes only, and should not be used in production.

此 Web 服务器仅用于开发目的,不应在生产中使用。

I can't emphasize this enough.

我怎么强调都不为过。

If you would like to use it with the Laravel server.phpfile you can head to your cli and start the server with the following command (from the root of your Laravel directory):

如果你想在 Laravelserver.php文件中使用它,你可以前往你的 cli 并使用以下命令(从你的 Laravel 目录的根目录)启动服务器:

php -S localhost:8000 server.php

You should then be able to head to localhost:8000in your web browser and begin using your Laravel application.

然后,您应该能够前往localhost:8000您的 Web 浏览器并开始使用您的 Laravel 应用程序。

Alternatively as Anand Capurmentioned you can launch the server with:

或者,正如Anand Capur提到的,您可以使用以下命令启动服务器:

php artisan serve

Ultimately this just runs the aforementioned php -Scommand for you.

最终,这只会php -S为您运行上述命令。

You can optionally specify the hostand portby doing something like:

您可以选择通过执行以下操作来指定hostport

php artisan serve --port=8080 --host=local.dev

As with all artisancommands you can find out this information and additional information by doing:

与所有artisan命令一样,您可以通过执行以下操作找到此信息和其他信息:

php artisan serve --help

回答by Anand Capur

You can also use the command

也可以使用命令

artisan servewhich will run the appropriate command to start the development server.

artisan serve这将运行适当的命令来启动开发服务器。