Adding vhosts to Apache 2 from a website

Discussion in 'Programming/Scripts' started by Leszek, Feb 20, 2007.

  1. Leszek

    Leszek Member

    Hello everyone!

    I need to make an interface on a website (the site would be on my server) to let visitors add an account for themselves for free. This would be a registration form, that after submitting would add a virtual hosts file to for example /etc/apache2/vhosts with correct definitions.The worst thing is that i can't work out a way to execute php scripts that would modify those files.
    I thought of executing a shell script from php,maybe using Cron for that job but it's too complicated for me at this time. I mean that a user would provide a username and a password by a form and php would save it to a file that would look like a shell script and Cron would execute it from time to time.
    Next thing i thought of was mod su_php to execute a php script,which would modify the needed files.I would like to know Your opinion about a way to securely add new vhosts to Apache.I need all info I can get from You more experienced people out there.Thanks in advance.

    My OS is Linux (preferrably OpenSuSE).
     
  2. ctql

    ctql New Member HowtoForge Supporter

    Store each vhost in a separate file (well, not a requirement but seems easier to manage) and put them all in a folder that apache can write to. Make sure apache reads this folder with something in the httpd.conf like:
    Include /etc/httpd/conf.d/vhosts/*.conf

    Then all you need to do is add a httpd reload script like the one I linked to here:
    http://www.howtoforge.com/forums/showthread.php?t=10597

    Of course, unless you trust your users a lot you'll want some verification that the data is good and that the newly generated config file can be used. You can do this by doing httpd configtest or reading the results of httpd reload...
     
  3. Leszek

    Leszek Member

    Well that's one way of doing this. I'll give it a shot in my free time.
    I'm still open for more suggestions.
    Thanks ctql!
     

Share This Page