rmartin
08-16-2001, 02:55 PM
Hello,
Could anyone please give me an example of how to modify the apache server conf file using a php or cgi script.
I am thinking in regards to how a web hosting control panel would make these modifications for creating new virtual servers etc
Many thanks in advance
R Martin
davidb
08-16-2001, 03:10 PM
Webmin has a ok interface for editing apache. I still prefer to do it by hand, but you might find it easier.
rmartin
08-16-2001, 03:18 PM
Thanks but i already use webmin for my main stuff
I was thinking more about the code itself for implementing a control panel for my users.
can anyone provide an example for me
Many Thanks
R Martin
tribby
08-16-2001, 03:55 PM
For PHP, see fwrite() (http://www.php.net/manual/en/function.fwrite.php)
For Perl, see open() (http://www.perldoc.com/perl5.6/pod/func/open.html)
Just open the httpf.conf file with whatever method you like and print to it...
Jeremy
cperciva
08-16-2001, 03:56 PM
*shudder*
Editing configuration files programatically is a very good way of shooting yourself in the foot.
Why not use mod_vhost_alias?
Gunzour
08-16-2001, 07:09 PM
Your conf file should be writable only by root (assuming Unix here), which means normal PHP and CGI scripts will not have access to modify it.
You can change the write permissions of the file, but that creates a big security risk.
If you really want to do this, I would suggest having your script modify a copy of httpd.conf, and then have a scheduled task that runs as root which does a configtest on the copy to make sure it's usable, then copies it over (making a backup of the old conf file), then does a graceful Apache restart.
You would need to be extremely careful writing such a program to make sure that it doesn't allow your customers to modify sites other than their own, either intentionally or by accident.
cperciva
08-16-2001, 07:28 PM
Originally posted by Gunzour
Your conf file should be writable only by root (assuming Unix here), which means normal PHP and CGI scripts will not have access to modify it.
You can change the write permissions of the file, but that creates a big security risk.
Or you can do things the right way, which is to use suEXEC to run your scripts under their owner's UID/GID, and have suid root code which is only executable from the appropriate "manager" group.