I changed my virtual host in Apache, now I can't get to any other directory.

I'm going through some Zend tutorials and at one point, I changed my httpd-vhost.conf file in Apache to this:

<VirtualHost *:80>
     ServerName tutorial.localhost
     DocumentRoot C:\wamp\www\zend_tutorial\public
     SetEnv APPLICATION_ENV "development"
     <Directory C:\wamp\www\zend_tutorial\public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

Now, I can't get out to any other directory, save my zend_tutorial without getting a page that a 404 error occurred. So, when I go out to localhost, I get my pretty little Zend page. But if I go out to localhost/SouthArea, I get a 404. In other words, every page is being processed according to my Zend directory and I don't want to do that.

I'm just following directions at this point without really understanding the ramifications of what I'm doing. What did I do when I changed my virtual host in my config file, how do I change it so I can access my other pages and how can I ensure that I access my Zend pages in the future? Do I have to change my virtual host?

Thanks!
Bruce GustPHP DeveloperAsked:
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.

Bruce GustPHP DeveloperAuthor Commented:
Alright, I've got my "regular" situation back and I did that by going back and commenting out my Virtual Host" line on my httpd-vhosts.conf, but...

Although I can see all my other sites, when I go to my Zend tutorial, which is at http://localhost/zend_tutorial/public/index.php, I get a "page not found" message.

Why is it that my Zend framework doesn't want to work apart from a Virtual Host entry on my Apache vhosts.conf file?
Steve BinkCommented:
The issue most likely resides in your use of the ServerName directive.  

The VirtualHost containers in Apache are used to allow Apache to respond to multiple domains with completely different sites.  Without a VirtualHost, EVERY request is going to the main service.  In 99% of cases, this is not a desired behavior.  To allow Apache to manage separate sites with unique names, we have to tell it which sites will be responding to which names.

When setting up the VirtualHost container, you are identifying it (normally) with an IP and port on which it should respond:
<VirtualHost 10.0.0.1:80>
  # some directives for site 1
</VirtualHost>
<VirtualHost 10.0.0.1:8080>
  # some directives for site 2
</VirtualHost>

Open in new window

In the example above, Apache will now have three sites to serve.  The first listens on IP 10.0.0.1 on port 80.  The second is on the same IP, but with port 8080.  The third is the "main" site, which exists inherently with Apache.  

That's all fine if you have a limited number of sites, or don't mind using a lot of different ports.  The problem here is that every browsing client in the world defaults to using port 80.  So, now you either need a large number of IPs, or a way to identify different sites using the same IP and port.  Enter the ServerName directive:
<VirtualHost 10.0.0.1:80>
  ServerName site1.localhost
  # some directives for site 1
</VirtualHost>
<VirtualHost 10.0.0.1:80>
  ServerName site2.localhost
  # some directives for site 2
</VirtualHost>

Open in new window

In this example, both of the virtual sites will listen on 10.0.0.1 with port 80.  The big difference is that each site will now respond ONLY to requests with an HTTP Host header matching the value provided for ServerName.  So, http://site1.localhost will go to virtual site 1, and http://site2.localhost will go to site 2.

The problem you encountered is that you created a VirtualHost with the ServerName equal to tutorial.localhost.  When you browse to http://localhost, the Host header is requesting a site named "localhost", not "tutorial.localhost".  So, the virtual site doesn't match, and will not serve the request.  Apache falls back to the "main" site, which serves as a catch-all.

There are two ways to resolve this:

1) Create a DNS entry for tutorial.localhost pointing to your localhost virtual site.  This is really unnecessary for what you're doing, though it would work.

2) Use a ServerName value that more closely matches what you're requesting, i.e., "localhost".

Any questions?

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
Bruce GustPHP DeveloperAuthor Commented:
Got it!
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
PHP

From novice to tech pro — start learning today.