Skip to content

Instantly share code, notes, and snippets.

@anthonyholmes
Last active December 14, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonyholmes/5167825 to your computer and use it in GitHub Desktop.
Save anthonyholmes/5167825 to your computer and use it in GitHub Desktop.
Create virtual host from command line Syntax: sudo ruby vhost [path] [url] Note: Paths of your folders may be different
#!/usr/bin/ruby
# Get the path in the Sites folder
path = ARGV[0]
# Get the path in the Sites folder
url = ARGV[1]
if ARGV[2] == "third"
open('/etc/apache2/extra/httpd-vhosts.conf', 'a') { |f|
f.puts ''
f.puts "<VirtualHost *:80>"
f.puts "\tDocumentRoot \"/Users/USER/Sites/#{path}\""
f.puts "\tServerName #{url}"
f.puts '</VirtualHost>'
}
open('/etc/hosts', 'a') { |f|
f.puts ''
f.puts "127.0.0.1 #{url}"
f.puts "fe80::1%lo0 #{url}"
}
exec('apachectl restart')
exit
end
exec "sudo ./vhost #{path} #{url} third"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment