Skip to content

[9.x] Allows to remove the server.php file #40034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class ServeCommand extends Command
*/
public function handle()
{
chdir(public_path());

$this->line("<info>Starting Laravel development server:</info> http://{$this->host()}:{$this->port()}");

$environmentFile = $this->option('env')
Expand Down Expand Up @@ -104,7 +102,7 @@ public function handle()
*/
protected function startProcess($hasEnvironment)
{
$process = new Process($this->serverCommand(), null, collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
$process = new Process($this->serverCommand(), public_path(), collect($_ENV)->mapWithKeys(function ($value, $key) use ($hasEnvironment) {
if ($this->option('no-reload') || ! $hasEnvironment) {
return [$key => $value];
}
Expand Down Expand Up @@ -132,11 +130,15 @@ protected function startProcess($hasEnvironment)
*/
protected function serverCommand()
{
$server = file_exists(base_path('server.php'))
? base_path('server.php')
: __DIR__.'/../resources/server.php';

return [
(new PhpExecutableFinder)->find(false),
'-S',
$this->host().':'.$this->port(),
base_path('server.php'),
$server,
];
}

Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Foundation/resources/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$publicPath = getcwd();

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

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

require_once $publicPath.'/index.php';