Page 1 of 1

Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 15:30
by HTHVampire
Hi,

When I try to enter localhost/uccn3004, I got an error 404. I already set up virtual host for my webpage and I'm able to access it using www.empire.com(virtual host name I created) but not for localhost/uccn3004. Besides that, my localhost/phpmyadmin also working fine.

Here's my configuration details:

1. My directory for htdocs and all my websites are stored in UCCN3004 folder
Image

2. My document root setting
Even I try to change the path to C:/xampp/htdocs/UCCN3004, it doesn't work as well.
Image

3. vhosts configuration
Image

4. Error found
Image

Can someone figure out any problems with my setting? Thank you very much!

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 16:49
by JJ_Tagy
Looking at your file structure, it is in UCCN3004 instead of uccn3004. Perhaps try to match the case?

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 17:20
by HTHVampire
JJ_Tagy wrote:Looking at your file structure, it is in UCCN3004 instead of uccn3004. Perhaps try to match the case?


Hi, thanks for the suggestion, I tried but it still can't access.

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 17:32
by JJ_Tagy
Revert back all your .conf changes and see if localhost works. Don't forget to stop/start apache. Then try UCCN3004 again. Also, do you have an index.php or similar in UCCN3004?

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 18:47
by Nobbie
When you specify even only ONE VirtualHost, all standard settings (outside from VirtualHosts) are IGNORED by Apache. instead, you *should* specify a VirtualHost for localhost as well (similar to your declaration for empire.com).

If you DO NOT specify a VirtualHost for localhost, Apache does NOT take the "external" settings of your ServerName etc., instead Apache simply takes the FIRST VirtualHost of your declared VirtualHosts. In your case, if you enter "localhost", Apache does not know that is meant by that and takes your first VirtualHost, and this the declaration of empire.com.

And the DocumentRoot of empire.com is NOT c:/xampp/htdocs - and therefore http://localhost/UCCN3004 yields to c:/xampp/htdocs/UCCN3004/UCCN3004 (you see, what is going wrong?!) and of course, Apache cannot find that. Instead, if you only enter http://localhost, this *should* show up your empire.com Host, and that yields to DocumentRoot c:/xampp/htdocs/UCCN3004

Try it and you will see, simply http://localhost will show your UCCN3004 files. Probably you dont want this behaviour, therefore add another VirtualHost for ServerName localhost and apply DocumentRoot c:/xampp/htdocs.

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 19:03
by HTHVampire
Nobbie wrote:When you specify even only ONE VirtualHost, all standard settings (outside from VirtualHosts) are IGNORED by Apache. instead, you *should* specify a VirtualHost for localhost as well (similar to your declaration for empire.com).

If you DO NOT specify a VirtualHost for localhost, Apache does NOT take the "external" settings of your ServerName etc., instead Apache simply takes the FIRST VirtualHost of your declared VirtualHosts. In your case, if you enter "localhost", Apache does not know that is meant by that and takes your first VirtualHost, and this the declaration of empire.com.

And the DocumentRoot of empire.com is NOT c:/xampp/htdocs - and therefore http://localhost/UCCN3004 yields to c:/xampp/htdocs/UCCN3004/UCCN3004 (you see, what is going wrong?!) and of course, Apache cannot find that. Instead, if you only enter http://localhost, this *should* show up your empire.com Host, and that yields to DocumentRoot c:/xampp/htdocs/UCCN3004

Try it and you will see, simply http://localhost will show your UCCN3004 files. Probably you dont want this behaviour, therefore add another VirtualHost for ServerName localhost and apply DocumentRoot c:/xampp/htdocs.


Hi Nobbie, I appreciate your help, since I'm still new to Apache, I truly appreciate the concepts you delivered here and finally I manage to get what I need. Thank you very much! same goes to HH_Tagy that tried to help, thank you.

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 19:20
by Nobbie
Finally, if you wonder why phpmyadmin works...

HTHVampire wrote:Besides that, my localhost/phpmyadmin also working fine.


... (as it should not work, due to the concepts explained before); the URL /phpmyadmin is not related to c:/xampp/htdocs/UCCN3004/phpmyadmin (this is, what you would expect now), because /phpmyadmin is overriden by a so called "ALIAS". See the documentation about ALIAS and you will find appropriate declaration in extras/httpd-xampp.conf (i am not 100% sure about that, but you will find out, where it is). ALIAS is kind of "special DocumentRoot" for a single URL (or virtual folder). The ALIAS is a very helpfully configuration, if you need to apply a document, what "normally" is outside of the scope of DocumentRoot.

Re: Apache cannot access to my localhost php webpage

PostPosted: 02. August 2015 21:14
by HTHVampire
Hi Nobbie,

Thanks for the further details explained. I learnt much from you, really appreciate your time to deal with my problem. Thank you!