Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to configure a VirtualHost for Apache with custom hosts settings without modifying /etc/hosts?

I want a VirtualHost to connect to a different host for testing then my live system. For example, in my /etc/hosts file I would have entries such as:

10.0.0.10    real_db

Where 10.0.0.10 is an IP for my test box and real_db is a link to the live system.

This is a setup I have to work with and changing the code to point to a different server would require touching couple of hundred files.

I am looking for a way to have Apache control which hosts are used depending on which VirtualHost I access.

My other alternative is to write a Bash script to comment/uncomment entries in /etc/hosts, though this approach relies on me remembering to actually do that. I would prefer to stick with something that does not require my input.

Thank you

share|improve this question

1 Answer 1

up vote 2 down vote accepted

No, it is not possible to have Apache httpd modify the DNS resolver settings (or sources) of the system.

Although it doesn't help you right now, you should have your software read its database settings from one configuration file or be able to use environment variables for this (which can be set with SetEnv in the Apache httpd configuration).

share|improve this answer
    
That's the model the code is being moved to, but there is a lot of code to move and the code is very fragile. I was hoping there was a simpler solution. Thanks –  Misha M Nov 5 '09 at 16:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.