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?
To begin with: remember that enabling web-applications to alter the server configuration is really a security risk.
# First, open the config file fd=File.open('/etc/apache2/sites/yoursite', 'r+') # read in the contents content=fd.read # now replace the ServerName and ServerAlias lines with your new setting if content.gsub!(/ServerName(.*)/,"ServerName NewServerName") and content.gsub!(/ServerAlias(.*)/,"ServerAlias NewServerAlias") fd.rewind puts "\tsaving file" fd.write content end fd.close
I didn't test neither code nor the standard expressions, please load the appropriate areas of your config file into rubular.com and roll your personal regex.
Perhaps you should also create a backup before saving using