Configuring Virtual Hosts on Fedora 16

I have F16 on a notebook that I'm setting up for web development. LAMP is running but I'm having difficulty setting up virtual hosts for each of the different projects I am working on.

It seems that each name points to the same docroot.
http://localhost should point to /var/www/html/ Where I've added an index.html file with a heading to indicate it's location.
http://test.dev should point to /var/www/html/test where I've added a different index.html file to indicate it's location.

However, when I access the test.dev domain in the browser I receive the /var/www/html/index.html file. I've tried setting up others but they all point to the html folder rather than the documentroot.

In /etc/httpd/conf/httpd.conf I have uncommented:
NameVirtualHost *:80

and at the bottom of the file I've added:
<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html/test
    ServerName test.dev
</VirtualHost>

In /etc/hosts I've added the following at the bottom of the file:
127.0.0.1 test.dev

Can you help me to resolve this?

Also I've read that it's better to establish dev environments in workspace rather than /var/www/html. Thoughts?

Thanks!!
TrinitySEMAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dmitriy SkyIT EngeneerCommented:
hmm

add
        ServerName www.test.dev
      ServerAlias test.dev *.test.dev


and put it on first place
0
TrinitySEMAuthor Commented:
Thanks for the reply. Still no success:

I added the elements above and reversed the order to:
<VirtualHost *:80>
    DocumentRoot /var/www/html/test
    ServerName www.test.dev
    ServerAlias test.dev *.test.dev
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName localhost
</VirtualHost>

Then I /etc/init.d/httpd restart
Then in browser http://test.dev or httpd://www.test.dev

www results in 404 and non www still points to incorrect location.
In httpd.conf I've tried commenting and uncommenting this line and neither helps:
DocumentRoot "/var/www/html"

Thanks again.
0
xtermCommented:
Apache is picky about this.  Use a NameVirtualHost as below, and it will work:
# REPLACE THE IP BELOW WITH YOUR OWN SYSTEM IP ADDRESS
NameVirtualHost 10.10.0.1

# MAIN SYSTEM ROOT
<VirtualHost my.server.hostname>
    DocumentRoot /var/www/html
    ServerName my.server.hostname
    ErrorLog logs/error_log
    CustomLog logs/access_log common
</VirtualHost>

# ALL YOUR VIRTUAL HOSTS GO BELOW
<VirtualHost www.test.dev
    DocumentRoot /var/www/html/test
    ServerName www.test.dev
    ServerAlias test.dev *.test.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

TrinitySEMAuthor Commented:
Thanks for your input. Still not working. Here is what I have now:

NameVirtualHost 127.0.0.1

# Main System Root
<VirtualHost localhost>
    DocumentRoot /var/www/html
    ServerName localhost
    ErrorLog logs/error_log
    CustomLog logs/access_log common
</VirtualHost>

# Virtual Hosts
<VirtualHost www.test.dev>
    DocumentRoot /var/www/html/test
    ServerName www.test.dev
    ServerAlias test.dev *.test.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>

Just to be safe, I'm including the entire httpd.conf for reference.
httpd.txt
0
xtermCommented:
You need test.dev or www.test.dev to resolve to 127.0.0.1 for this to work.

What happens if you ping test.dev or www.test.dev?
0
TrinitySEMAuthor Commented:
http://www.test.dev resolves to 404 "Chrome could not find "www.test.dev".

When I ping www.test.dev I receive: ping: unknown host www.test.dev
0
xtermCommented:
You can't just make up names in Apache - they have to be set up in DNS to drive the web requests to the correct place first.

If you are running your web browser on the SAME machine as the Apache server, then you can modify localhost in /etc/hosts as:


127.0.0.1                       localhost       test.dev  www.test.dev


That will make your machine be able to ping and access those names in a browser.
0
TrinitySEMAuthor Commented:
Progress.  When I add www. test.dev to hosts test.dev is accessible via http://test.dev and http://www.test.dev.
Thank you.


However...

When I add a new project called "drupal.dev", and access http://drupal.dev or http://www.drupal.dev I'm not getting index.php on /var/www/html/drupal but rather localhost index.html. Test.dev is still working correctly though so that is good. Here's what I added:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 test.dev www.test.dev drupal.dev www.drupal.dev
::1         localhost6 localhost6.localdomain6

and

<VirtualHost www.drupal.dev>
    DocumentRoot /var/www/html/drupal
    ServerName www.drupal.dev
    ServerAlias drupal.dev *.drupal.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>

then

/etc/init.d/httpd restart



0
TrinitySEMAuthor Commented:
Don't know if this has any impact but FWIW when I named the system I called it x120e.localdomain. When I look at hostname for system it is that.
0
xtermCommented:
What if you put "index.html" in /var/www/html/drupal ?  Does it load that?

The web server may not be set up to autoload index.php, so it would give you the test page in that circumstance.
0
xtermCommented:
Your system hostname isn't relevant to this issue.
0
TrinitySEMAuthor Commented:
When I copy index.html to drupal I also receive localhost instead.
0
xtermCommented:
Can I please see your httpd.conf starting from the line NameVirtualHost?
0
TrinitySEMAuthor Commented:
Yes, here it is:

# NameVirtualHost *:80
NameVirtualHost 127.0.0.1
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of they
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
# You can also add ServerAlias if you want to use www. Example:
# ServerAlias www.example.com

# Main System Root
<VirtualHost localhost>
    DocumentRoot /var/www/html
    ServerName localhost
    ErrorLog logs/error_log
    CustomLog logs/access_log common
</VirtualHost>

# Virtual Hosts
<VirtualHost www.test.dev>
    DocumentRoot /var/www/html/test
    ServerName www.test.dev
    ServerAlias test.dev *.test.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>
<VirtualHost www.drupal.dev>
    DocumentRoot /var/www/html/drupal
    ServerName www.drupal.dev
    ServerAlias drupal.dev *.drupal.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>
0
xtermCommented:
You have overlapping logs, but that shouldn't affect the site's operation.  Either way, I'd change them to drupal-error.log and drupal-access.log

Then reload httpd, and see which log file grows when you are hitting the drupal site in a web browser.

Also please see what it says in the /var/log/httpd/error_log when you hit the page:

  tail -f /var/log/httpd/error_log

(hit CTRL-C to get out of that.. it will show you the last few lines of that log file, and it will scroll when new errors appear)
0
TrinitySEMAuthor Commented:
I revised the error logs for test and drupal as recommended.

when i access drupal.dev with the browser tail -f /var/log/httpd/error_log yields:
[Wed Dec 21 17:24:49 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico

When i access drupal.dev with browser and tail -f /var/log/httpd/drupal-error.log I get:
tail: cannot open `/var/log/httpd/drupal-error.log' for reading: No such file or directory

When I touch /var/log/httpd/drupal-error.log then tail I no longer receive the above error but nothing is reported.

Seems it is defaulting to localhost.


0
xtermCommented:
Just out of curiosity, what happens if you switch these two virtual hosts' order in httpd.conf and restart httpd?
# Virtual Hosts
<VirtualHost www.test.dev>
    DocumentRoot /var/www/html/test
    ServerName www.test.dev
    ServerAlias test.dev *.test.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>

<VirtualHost www.drupal.dev>
    DocumentRoot /var/www/html/drupal
    ServerName www.drupal.dev
    ServerAlias drupal.dev *.drupal.dev
    ErrorLog logs/dev-error.log
    CustomLog logs/dev-access_log common
</VirtualHost>

Open in new window

0
TrinitySEMAuthor Commented:
good idea. I switched them and get nothing from tail in drupal but continue to get info from tail on localhost when accessing drupal.dev or www.drupal.dev.

in localhost i initially get this message:

[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 4978 for worker proxy:reverse
[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 4978 for (*)
[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 0 in child 4979 for worker proxy:reverse
[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1837): proxy: worker proxy:reverse already initialized
[Wed Dec 21 17:38:54 2011] [debug] proxy_util.c(1934): proxy: initialized single connection worker 0 in child 4979 for (*)
[Wed Dec 21 17:39:23 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico
[Wed Dec 21 17:39:26 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico
[Wed Dec 21 17:39:32 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico
[Wed Dec 21 17:39:38 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico

and when I access drupal.dev via browser I get:
[Wed Dec 21 17:40:28 2011] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico


0
Dmitriy SkyIT EngeneerCommented:
you forget to add :80 >_< in VirtualHost, and it's not realy need to create new virtualhost, you can use one, but create many of ServerAlias ...


hmm???? wait..

first File does not exists, not a problem, just favicon, BUT
first you use proxy to connect to web? via localhost, thats a problem, u must enter as www.drupal.dev and www.test.dev

also check that you realy use httpd.conf, and check apache2/sites-avialable/default, if that file exits, they contain settings..

problem that u get /var/www/html/* >_< so.. check that u not mistake older configuration somewhere.
0
TrinitySEMAuthor Commented:
the :80 made no difference.

I've tried both www and non www versions of URL and neither works. I get a 404 on the www version and with the exception of test.dev I get localhost for all others.

I think apache2/sites-available/default is a Debian thing. Fedora doesn't have. Debian also has a2siteenable which simplifies all of this.

Unfortunately It's still in the same state.

Thanks again for your persistence and help.
0
TrinitySEMAuthor Commented:
Oh, forgot to add that I'm not using a proxy.

Also, what do you mean by this?:

problem that u get /var/www/html/* >_< so.. check that u not mistake older configuration somewhere

Thanks!

0
TrinitySEMAuthor Commented:
it's not realy need to create new virtualhost, you can use one, but create many of ServerAlias ...

Though each as a different doc root so i'm not certain how I would structure that. Thoughts?
0
xtermCommented:
You can't have different DocumentRoot's within a single site, you have to have a virtualhost for each one if you want different content trees.
0
TrinitySEMAuthor Commented:
Agreed. That is why I have one for each site.

After some further testing here is what I've done:

in /etc/httpd/conf/httpd.conf uncomment the following line:
NameVirtualHost *:80
Create a directory (eg: /var/www/html/example )
In /etc/hosts add example.dev
in terminal run system-config-httpd
add the virtual host by specifiying the following:
Virtual Host Name: Example
Document Root Directory: path to directory
IP Address: 127.0.0.1
Host Name: example.com
In the case of Drupal go to "Page Options" tab and add "index.php" to the Directory Page Search List
/etc/init.d/httpd restart

When I do above I'm able to access:

http://test.dev
http://drupal.dev
http://localhost

www version results in a 404 but I don't see that as much of an issue.

0
TrinitySEMAuthor Commented:
I think the above is a reasonable workaround for now but I still am curious about why the other approach wouldn't work.
0
TrinitySEMAuthor Commented:
I had another thought in regards to system-config-httpd. With it installed, I wonder if there are additional files involved that may be conflicting with hosts and httpd.conf.
0
xtermCommented:
No, that program will not interfere with anything...it strictly edits.
0
TrinitySEMAuthor Commented:
It turns out that system-config-httpd Gui Tool was interfering with my efforts. It creates an additional conf file at  /etc/httpd/conf.d/system-config-httpd.conf  and when editing /etc/httpd/conf/httpd.conf it created conflicts. I have uninstalled the GUI Tool and have deleted the additional conf file and am now editing /etc/hosts and /etc/httpd/conf/httpd.conf files directly and the virtualhost configuration is working correctly.
0
xtermCommented:
Great catch - that's unfortunately the problem with those GUI front-ends - they introduce new variables which would never come up if you were to simply hand-configure them.  Glad you're all working, and hope our help was valuable along the way!
0
TrinitySEMAuthor Commented:
Closing this and awarding points. Thank you both for your input and xterm for your time and persistence.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.