Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:    real_db

Where 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
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


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.