我实际上在我过去的项目中做了这个并且它正在工作,但它现在是一个新版本6.0,我以前使用的是5.8。
所以我尝试了什么,我只是创建了一个命令:
php artisan make:command CustomServeCommand
我将这些代码放在CustomServeCommand类中:
protected function getOptions()
{
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', '127.0.1.1'],//default 127.0.0.1
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 80],
];
}
当我php artisan serve
它不起作用时。
实际上,上面的代码在5.8版本中工作,返回这些行:
Laravel development server started: <http://127.0.1.1:80>
相反127.0.0.1:8000
,我想服务127.0.1.1:80
。
有谁知道如何实现这一目标?
注意:这只是为了减少帖子,我不打算在图片中发布代码。
因为在5.8
您扩展现有命令的版本中,composer在您自己之前加载的命令中,6.0
您不是
serve
像这样扩展现有的命令
<?php
namespace App\Console\Commands;
use Illuminate\Foundation\Console\ServeCommand;
use Symfony\Component\Console\Input\InputOption;
class CustomServeCommand extends ServeCommand
{
protected function getOptions()
{
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', '127.0.1.1'], //default 127.0.0.1
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 80],
];
}
}
并且不注册命令Console\Kernel
你的端口选择有点奇怪,所以你必须做几件事
sudo service nginx stop
# or
sudo service apache2 stop
sudo php artisan serve
~/Sites/laravel (master ✗) ✹ ★ ᐅ sudo php artisan serve
Laravel development server started: <http://127.0.1.1:80>
[Thu Sep 26 18:04:02 2019] Failed to listen on 127.0.1.1:80 (reason: Address already in use)
~/Sites/laravel (master ✗) ✹ ★ ᐅ sudo service nginx stop
~/Sites/laravel (master ✗) ✹ ★ ᐅ sudo php artisan serve
Laravel development server started: <http://127.0.1.1:80>
^C
~/Sites/laravel (master ✗) ✹ ★ ᐅ php artisan serve
Laravel development server started: <http://127.0.1.1:80>
[Thu Sep 26 18:04:23 2019] Failed to listen on 127.0.1.1:80 (reason: Permission denied)
~/Sites/laravel (master ✗) ✹ ★ ᐅ sudo php artisan serve
Laravel development server started: <http://127.0.1.1:80>
[Thu Sep 26 18:10:28 2019] 127.0.0.1:58714 [200]: /robots.txt
[Thu Sep 26 18:10:29 2019] 127.0.0.1:58716 [200]: /favicon.ico
另外,我建议给Laravel Valet一个机会(适用于 Mac 和 Linux),因为它更容易在project.test
没有任何命令的情况下访问
尽管如此,我希望这会有所帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句