Laravel homestead and vagrant-hostsupdater - Automate the hosts file updation in windows for your next homestead project!
Published by Aslam
Lets configure homestead.rb to update hosts file using hostsupdater plugin.
in case if you have not yet added this plugin, run
Open homestead.rb file in your favorite text editor.
Find this block at the end, (You can set anywhere but i prefer to add my customizations at the end of the file.)
Now, lets add hosts in "Homestead.yaml" , usually located in (user.homestead) directory.
Find the site you want to update hosts for.
at the end of "Homestead.yml", Add
Close vagrant if already opened with.
And you will be able to access "yourdevdomain.app".
You can check the "hosts" file, to see the host is updated.
vagrant plugin install vagrant-hostsupdater
from your command prompt.Open homestead.rb file in your favorite text editor.
Find this block at the end, (You can set anywhere but i prefer to add my customizations at the end of the file.)
# Configure Blackfire.io
if settings.has_key?("blackfire")
config.vm.provision "shell" do |s|
s.path = scriptDir + "/blackfire.sh"
s.args = [
settings["blackfire"][0]["id"],
settings["blackfire"][0]["token"],
settings["blackfire"][0]["client-id"],
settings["blackfire"][0]["client-token"]
]
end
end
And add following code snippet next to the code above.# Updating the hosts file with all the sites that are defined in Homestead.yaml
if Vagrant.has_plugin?("vagrant-hostsupdater") && settings["hosts_file_additions"] == true
hosts = []
settings["sites"].each do |site|
hosts.push(site["map"])
end
config.hostsupdater.aliases = hosts
end
Save the file.Now, lets add hosts in "Homestead.yaml" , usually located in (user.homestead) directory.
Find the site you want to update hosts for.
sites:
- map: yourdevdomain.app
to: /home/www/laravel/public
hosts: 192.168.88.88
"hosts: 192.168.88.88" is the IP we want our "map: yourdevdomain.app" to be pointed to.at the end of "Homestead.yml", Add
hosts_file_additions: true
Save the file.Close vagrant if already opened with.
vagrant halt
Run the vagrant up --provision
command.And you will be able to access "yourdevdomain.app".
You can check the "hosts" file, to see the host is updated.
Comments
Post a Comment