'How to set a domain name with php artisan serve

I am new to PHP and Laravel. While virtualhosting with Wamp, I could specify the documentroot, servername and the port number - hence specifying the domain name. But with the command php artisan serve, I am able to specify the port address but not the domain name. Is it possible to set the domain name?

also, what is the difference between hosting with this command and with wamp ?

n.b I am new to server side languages, sorry for asking these basics !

EDIT: I've used php artisan serve --host=blog.local --port=8001 but error is showing upenter image description here

I've cleared the configuration and application cache.



Solution 1:[1]

You can explicitly define the host and the port with artisan serve command:

php artisan serve --host=somedomain.com --port=8001

Note: Remember to enable to port with your firewall.

Solution 2:[2]

Though it is too late.

Make an entry in the system host file. in case of windows it is at

C:\Windows\System32\Drivers\etc\hosts


# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
127.0.0.1           blog.local

Then run your command:

php artisan serve --host=blog.local --port=8001

Solution 3:[3]

It's easy, just pass the --host parameter.

php artisan serve --host=example.com

Solution 4:[4]

Try to command like this:

php artisan serve --host=<host IP address> --port=<port to use>

Example:

php artisan serve --host=127.0.0.1 --port=8080

Solution 5:[5]

First of all you will need to add your local domain in the host file. The path is C:\Windows\System32\drivers\etc and you will found the host file.

Open with notepad and write this line 127.0.0.1 <your_domain_name> to the last line. For example 127.0.0.1 lala.com

Then the command on your terminal,

php artisan serve --host=<your_domain_name_in_the_host_file> 

and system will auto generate a port number for you like

php artisan serve --host=lala.com
Laravel development server started: http://lala.com:8000

Now then, you are able to surf your localhost, which is http://lala.com:8000 with your custom domain name but also with the port number.

If you want a custom port number then just specify the port number at the end of the command,

php artisan serve --host=lala.com --port=8088 

and url will be http://lala.com:8088

Solution 6:[6]

php artisan serve --host=0.0.0.0 --port=8000

Solution 7:[7]

You can try it: php artisan serve --host 192.168.0.1 --port 80

Change your host and port

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saurabh
Solution 2 Srijib Mandal
Solution 3 mayank
Solution 4 Joe Mayo
Solution 5
Solution 6 David Faizulaev
Solution 7 illeas