Skip to content

Commit 94e846b

Browse files
[9.x] Allows to remove the server.php file (#40034)
* Allows to remove the `server.php` file * Apply fixes from StyleCI Co-authored-by: Taylor Otwell <taylorotwell@users.noreply.github.com>
1 parent 8dde758 commit 94e846b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Illuminate/Foundation/Console/ServeCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class ServeCommand extends Command
4949
*/
5050
public function handle()
5151
{
52-
chdir(public_path());
53-
5452
$this->line("<info>Starting Laravel development server:</info> http://{$this->host()}:{$this->port()}");
5553

5654
$environmentFile = $this->option('env')
@@ -104,7 +102,7 @@ public function handle()
104102
*/
105103
protected function startProcess($hasEnvironment)
106104
{
107-
$process = new Process($this->serverCommand(), null, collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
105+
$process = new Process($this->serverCommand(), public_path(), collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
108106
if ($this->option('no-reload') || ! $hasEnvironment) {
109107
return [$key => $value];
110108
}
@@ -132,11 +130,15 @@ protected function startProcess($hasEnvironment)
132130
*/
133131
protected function serverCommand()
134132
{
133+
$server = file_exists(base_path('server.php'))
134+
? base_path('server.php')
135+
: __DIR__.'/../resources/server.php';
136+
135137
return [
136138
(new PhpExecutableFinder)->find(false),
137139
'-S',
138140
$this->host().':'.$this->port(),
139-
base_path('server.php'),
141+
$server,
140142
];
141143
}
142144

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
$publicPath = getcwd();
4+
5+
$uri = urldecode(
6+
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
7+
);
8+
9+
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
10+
// built-in PHP web server. This provides a convenient way to test a Laravel
11+
// application without having installed a "real" web server software here.
12+
if ($uri !== '/' && file_exists($publicPath.$uri)) {
13+
return false;
14+
}
15+
16+
require_once $publicPath.'/index.php';

0 commit comments

Comments
 (0)