Created
January 31, 2018 07:32
-
-
Save ejlocop/2e81cd3134fbc6b7858f28eb6fd4a60f to your computer and use it in GitHub Desktop.
set a default laravel php artisan serve host and port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Illuminate\Foundation\Console; | |
use Illuminate\Console\Command; | |
use Symfony\Component\Process\ProcessUtils; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Process\PhpExecutableFinder; | |
class ServeCommand extends Command | |
{ | |
/** | |
* The console command name. | |
* | |
* @var string | |
*/ | |
protected $name = 'serve'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Serve the application on the PHP development server'; | |
/** | |
* Execute the console command. | |
* | |
* @return void | |
* | |
* @throws \Exception | |
*/ | |
public function fire() | |
{ | |
chdir($this->laravel->publicPath()); | |
$host = $this->input->getOption('host'); | |
$port = $this->input->getOption('port'); | |
$base = ProcessUtils::escapeArgument($this->laravel->basePath()); | |
$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); | |
$this->info("Laravel development server started on http://{$host}:{$port}/"); | |
passthru("{$binary} -S {$host}:{$port} {$base}/server.php"); | |
} | |
/** | |
* Get the console command options. | |
* | |
* @return array | |
*/ | |
protected function getOptions() | |
{ | |
$host = env('SERVE_HOST', '127.0.0.1'); | |
$port = env('SERVE_PORT', 8080); | |
return [ | |
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', $host], | |
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', $port], | |
]; | |
} | |
} |
Just Replace the getOptions function in ServeCommand.php with the bellow line
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on', Env::get('SERVER_HOST')],
and create SERVER_HOST & SERVER_PORT variable into .env fle
SERVER_HOST=myproject
SERVER_PORT=80
****** defined SERVER_PORT in .env file not set different port if it already used.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add these two line to ServeCommand.php file
then create a SERVE_HOST and SERVE_PORT in your .env file