Php artisan serve require fatal error after upgrading php7

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


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 IlluminateFoundationConsole;

use IlluminateConsoleCommand;
use SymfonyComponentConsoleInputInputOption;

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.

链接地址: http://www.djcxy.com/p/69428.html

上一篇: 解析错误:语法错误,意外的T

下一篇: Php artisan服务在升级php7后需要致命错误