Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Forked from anonymous/rakefile.rb
Created December 10, 2010 11:48
Show Gist options
  • Save mrchrisadams/736118 to your computer and use it in GitHub Desktop.
Save mrchrisadams/736118 to your computer and use it in GitHub Desktop.
#I am using the port install apache version
#on top of that i have the debian structure of sites-enabled and sites-available simply
#by creating symlink from one folder to another
vhost_config_path = "/opt/local/apache2/conf"
desc "make vhost "
task :vhost_create do
require 'erb'
@site_domain = ENV["domain"]
@site_name = ENV["name"]
puts "The vhost name is #{@site_name} and the url is #{@site_domain}"
vhost_config_file = ERB.new(File.read(FileUtils.getwd + '/vhost.conf.erb')).result(binding)
File.open(FileUtils.getwd + "/#{@site_name}.vhost.conf", 'w') do |vhost_file|
vhost_file << vhost_config_file
end
sh "sudo mv #{@site_name}.vhost.conf #{vhost_config_path}/sites-available/#{@site_name}.conf"
end
desc "move vhost to appropriate folder and create syslink to sites-enabled"
task :vhost_enable do
@site_name = ENV["name"]
sh "sudo ln -s #{vhost_config_path}/sites-available/#{@site_name}.conf #{vhost_config_path}/sites-enabled/#{@site_name}.conf"
end
desc "disable vhost"
task :vhost_disable do
@site_name = ENV["name"]
sh "sudo rm #{vhost_config_path}/sites-enabled/#{@site_name}.conf"
end
desc "add new url to host file"
task :host_add do
domain_host = "\n127.0.0.1 #{@site_domain}"
File.open("/etc/hosts", 'a') do |host_file|
host_file << domain_host
puts "Host file updated"
end
end
desc "restart apache"
task :apache_restart do
#this path needs to be configured to point to your own httpd
sh "sudo /opt/local/apache2/bin/httpd -k restart"
puts "Apache restarted"
end
desc "enable a vhost and restart apache"
task :site_enable => [:vhost_enable, :apache_restart] do
puts "#{@site_name} has been enabled"
end
desc "disable a vhost and restart apache"
task :site_disable => [:vhost_disable, :apache_restart] do
puts "#{@site_name} has been disabled"
end
desc "creating a new site locally"
task :site_create => [:vhost_create, :site_enable, :host_add] do
puts "#{@site_name} has been created with the url htt://#{@site_domain}"
end
<VirtualHost *:80>
ServerName <%= @site_domain %>
ServerAdmin admin@<%= @site_domain %>
DocumentRoot "/Users/shakur/Sites/<%= @site_name %>"
<Directory />
Options FollowSymLinks
AllowOverride all
Order deny,allow
#Deny from all #This is the original line
Allow from all #Changed to this line
Satisfy all
</Directory>
ErrorLog "/var/log/sites/<%= @site_name %>.local-error_log"
CustomLog "/var/log/sites/<%= @site_name %>.local-access_log" common
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment