问题
After upgrading php from 7.0.14 to 7.0.26 php artisan serve
throws this error
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0 Fatal error: Unknown: Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/school-dashboard/public/server.php' (include_path='.:') in Unknown on line 0
回答1:
Ok, after hours of pulling my hair out I finally found out what the issue was.
In laravel 4 php artisan serve
does this under the hood
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class ServeCommand extends Command {
public function fire()
{
$this->checkPhpVersion();
chdir($this->laravel['path.base']);
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$public = $this->laravel['path.public'];
$this->info("Laravel development server started on http://{$host}:{$port}");
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" server.php");
}
}
That is essentially this in plain php:
php -S 127.0.0.1:8000 -t public serve.php
- see the docs for php built in server for more info.
And this worked well and dandy before php 7.0.26, where the last parameter for the php -S
built in server was changed to a flag as well, so you have to call it like this php -S 127.0.0.1:8000 -t public -f serve.php
.
If you want to serve it with php artisan serve
you will have to override the ServeCommand
and change the last line of the fire()
method to this:
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");
Or you can change it directly in the ServeCommand
, but if you do a composer update or install you will have to do it again.
回答2:
That's what it happened to me today running a Laravel project. After i have tried all the possible solutions finally i got one that it's work for me . So first of all check that your anti-virus block your server.php and it also deleting it . Then check if you server.php is missing from your project, and I think that is probably yes . Just copy it (server.php) from other project (build also from laravel) but before that just turn off your anti-virus until your next restart and make you sure that you will stop it every time before running. I hope that it helps you.
来源:https://stackoverflow.com/questions/47670251/php-artisan-serve-require-fatal-error-after-upgrading-php7