Last active
December 14, 2015 23:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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