Apache changing /etc/hosts?

Discussion in 'Server Operation' started by sparky87, Mar 8, 2009.

  1. sparky87

    sparky87 New Member

    i would like to make something like creating subdomains on my Apache server.
    it can only work, when i create a config file for every subdomains, or i add to httpd-vhosts something like this
    <VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/www/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
    </VirtualHost>

    but what i have to do too, is, change the /etc/hosts file.
    add something like, for example: 127.0.0.1 dummy-host2.example.com

    the question is, how can i do this from some php script? when the user comes, wants to registrate himself -> by this registration i have to do those things written above, and he will have his subdomain. but, i cannot change /etc/hosts file, because it is owned by root, and php scripts are running under some apache user.

    i dont know, if this is possible to make with suid and how is it possible...
    pls, how can i do this?

    thanks for answers
     
  2. matey

    matey New Member

    I think may be you can chmod the files or the whole directory under /etc/ to include reg. users?!
    I had to do this once using Zope (although zope makes its own user in proc. of installation)...

    I am not sure it is such a good idea, and I am not sure if you have access as root yourself?
    May be someone who knows more than me can help you?
    good luck
     
  3. id10t

    id10t Member

    You don't need to modify /etc/hosts when you add a virtual host... as long as DNS points to your IP apache will respond with the content for that name.

    BTW - recommend putting each vhost in its own config under /etc/apache2/sites-available and then putting a link to it in /etc/apache2/sites-enabled

    Also while I know how to hand create all the needed files for domain hosting (dns, web, email) I've found great joy in relaxing and just using ispconfig ...
     
  4. sparky87

    sparky87 New Member

    to matey:
    thanks, i can chmod the files under /etc/ and it will work, of course. but i am not really sure, if it is secure and good to do it so. what do you think? i don't know...

    to id10t:
    well, i put each vhost in its own config -> these files are saved in /www/conf/vhosts and in file /www/conf/extra/httpd-vhosts.conf is this: Include conf/vhosts, what says, where apache has to look for vhosts config files. -> but i have to modify /etc/hosts too, like i wrote above...
    but you say, i don't need to modify /etc/hosts. in fact, i dont understand this very well. the problem is, i don't have any DNS system so i cannot use A records. this system works only on my localhost - in this case i need to modify /etc/hosts . or is it possible to do it without that????
     
  5. matey

    matey New Member

    sparky87;

    As I said I had this problem with Zope but I am using this machine all by myself so no one else has any access to it therefore I do not know what happens?
    I made it work though but again I made a mistake when I set up zope and installed it under /root directory!?
    then I had to do chmod +x /root/zope/ to give the zope user the access...

    so if you are in a situation where a lot of others (human users) have access to your machine then I would not do that, or just copy the (config) files you want to try (not the whole folder) to a safe location so you can later move them back in case some thing happened.
    It's always a good thing to copy files for safe-keeping any way
    Good Luck.
     
  6. sparky87

    sparky87 New Member

    to matey:
    ok, thanks for your advices. when i won't find out any another way hot do it, i will do, what you say.

    but when someone has some another idea, just let me know :)
     

Share This Page