Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default url from localhost:8000 to other Ip in laravel when we run "php artisan serve"

Tags:

php

laravel-5

I am running php artisan serve command

by default the result is :

Laravel development server started: http://127.0.0.1:8000

I want to change pointing to other ip

like image 831
Bhulawat Ajay Avatar asked Sep 28 '17 12:09

Bhulawat Ajay


2 Answers

# php artisan serve --help
Usage:
  serve [options]

Options:
      --host[=HOST]     The host address to serve the application on. [default: "127.0.0.1"]
      --port[=PORT]     The port to serve the application on. [default: 8000]
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Serve the application on the PHP development server
like image 152
Devon Avatar answered Sep 30 '22 02:09

Devon


To change default host and/or port for the artisan serve command, you need to edit the ServeCommand.php file:

$ sudo nano vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php

At the end of it you will find were they are configured:

    protected function getOptions()
    {
        return [
            ['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on', '127.0.0.1'],
            ['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on', '8000'],
        ];
    }

Just change de default value of the host 127.0.0.1 for the ip of your desired host. And 8000 for the number of your desired port.

My case: I have an UbuntuServer 18.04 VM running over GoogleCloud - ComputeEngine, I was unable to see the Laravel execution until I changed the host to 0.0.0.0, of course I changed the port as well to have the 80 as default.

The alternative was executing every time:

$ sudo php artisan serve --host=0.0.0.0 --port=80

in order to obtain the same result.

like image 32
AtomicNation Avatar answered Sep 30 '22 03:09

AtomicNation