Skip to content

Instantly share code, notes, and snippets.

@jess
Created December 28, 2011 12:35
Show Gist options
  • Save jess/1527807 to your computer and use it in GitHub Desktop.
Save jess/1527807 to your computer and use it in GitHub Desktop.
# This is a script I use to create a virtual host on my development Ubuntu machine
class VH
def self.create(domain, location)
dev = domain.split(".").insert(1, "dev").join(".")
if location.nil?
doc_root = "DocumentRoot /home/jess/virtual/#{domain}"
else
doc_root = "DocumentRoot #{location}"
end
host = "
<VirtualHost *:80>
ServerName #{domain}
ServerAlias #{dev}
#{doc_root}
</VirtualHost>"
File.open('/etc/apache2/sites-available/' + domain, 'w') {|f| f.write(host) }
cmd = "a2ensite #{domain}; /etc/init.d/apache2 reload"
%x[#{cmd}]
end
end
while(true)
print 'Enter [Domain] [Location]> '
input = gets.split
domain = input[0]
location = input[1] unless input[1].nil?
unless domain==""
exit if domain=="exit" || domain=="quit"
d = VH.create(domain, location)
puts "Virtual Host for #{domain} created (remember to restart apache rails env dev?)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment