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

<?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中找不到任何提到它或它的用途的东西.

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.php file seems like it may be a stop-gap solution to do just that.

如果server.php文件的目的真的是为了模拟Apache的mod_rewrite功能,那么有人能解释一下它的用途以及如何使用/激活它吗?

推荐答案

它打算与PHP5.4中引入的PHP's internal web server一起使用.

根据PHP手册:

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

我怎么强调都不过分.

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

php -S localhost:8000 server.php

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

或者,如前所述,您可以通过以下方式启动服务器:

php artisan serve

最终,这将为您运行前面提到的php -S命令.

You can optionally specify the host and port by doing something like:

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

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

php artisan serve --help

Laravel相关问答推荐

为什么在Blade 文件中输出用户通知时出现错误?

Livewire 3分页在点击后不更新页面

如何传递多个参数给路由

如何在 Laravel 中使用内存数据库的完整测试套件之前迁移和 seeder ?

laravel 关系集合上的自定义排序

Laravel 不验证是否不需要字段

Laravel 附加额外字段

在 laravel 的集合中找到?例子

克隆后设置 Laravel 项目

如何在 Laravel 5.5 中扩展 vendor 包服务提供者

artisan 迁移错误找不到类'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver'

无法安装 Laravel 包 - 干预图像

如何在 laravel blade中进行一次性推送

在 Laravel 中显示已注册的路由

如何更改默认 Laravel Auth 登录视图

Laravel:在另一个控制器中加载方法而不更改 url

Laravel Queue,Beanstalkd vs Database,有什么区别?

在 Laravel artisan 命令中使用详细

在 laravel 中安装 vue 3.0

如何使用队列设置高、低和中优先级Electron邮件?