【问题标题】:What is the purpose of the server.php file in Laravel 4?Laravel 4 中 server.php 文件的用途是什么?
【发布时间】:2013-05-30 23:20:00
【问题描述】:

在 Laravel 4 的 /app/ 目录下,有一个名为 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';

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

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

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

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    它旨在与 PHP 5.4 中引入的PHP's internal web server 一起使用。

    根据PHP手册:

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

    我怎么强调都不过分。

    如果您想将它与 Laravel server.php 文件一起使用,您可以前往您的 cli 并使用以下命令(从 Laravel 目录的根目录)启动服务器:

    php -S localhost:8000 server.php
    

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

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

    php artisan serve
    

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

    您可以选择指定hostport,方法如下:

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

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

    php artisan serve --help
    

    【讨论】:

      【解决方案2】:

      你也可以使用命令

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-15
        • 2020-05-06
        • 2018-03-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多