Problem
You need fake hostnames.
You need to use different hostnames to test multiple Laravel applications but don't want to set up the hostnames in a DNS server. Instead, you want to use an internal hostname.
Solution
Edit your hosts file.
The following examples illustrate adding myapp.localhost.com pointing to IP address 192.168.100.100.
Editing the Hosts file in Linux
laravel:~$ sudo vi /etc/hosts
Add the line to the file:
192.168.100.100 myapp.localhost.com
Save the file then flush the DNS
laravel:~$ sudo service dns-clean start
Editing the Hosts file in OS X
$ sudo nano /private/etc/hosts
Add the line to the file:
192.168.100.100 myapp.localhost.com
Save the file then flush the DNS
$ dscacheutil -flushcache
Editing the Hosts file in Windows
Open a command prompt with administrator priveleges.
Then ...
C:\Windows\System32>cd \Windows\System32\drivers\etc
C:\Windows\System32\drivers\etc>notepad hosts
Add the line to the file:
192.168.100.100 myapp.localhost.com
Save the file, then from the administrator command prompt, flush the dns.
C:\Windows\System32\drivers\etc>ipconfig /flushdns
Discussion
There are conventions for naming internal hostnames.
For example, here are several variations for an application named MyApp.
- myapp.local
- myapp.dev
- myapp.localhost.com
Keep in mind if you're developing Laravel applications using a Vagrant box, you must edit the hosts file both in the box (the Linux instructions) and in your host operating system. This allows the web server to provide the correct virtual host within the vagrant box and allows you to use your browser on your host operating system to access that virtual host.
