My application is some two rails programs. According to some parameters in first application. I have to setup the virtual host from the second application. I simply need to alter the ServerName and ServerAlias in apache VH and let the website using a2ensite after which 'apache2 reload '.

How do i do that from inside a rails application?

Thanks, Imran

To begin with: remember that enabling web-applications to alter the server configuration is really a security risk.

#  First, open the config file'/etc/apache2/sites/yoursite', 'r+')
#  read in the contents
#  now replace the ServerName and ServerAlias lines with your new setting
if content.gsub!(/ServerName(.*)/,"ServerName NewServerName") and content.gsub!(/ServerAlias(.*)/,"ServerAlias NewServerAlias")
  puts "\tsaving file"
  fd.write content

I didn't test neither code nor the standard expressions, please load the appropriate areas of your config file into and roll your personal regex.

Perhaps you should also create a backup before saving using