VirtualHosts configuration - only partially working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

VirtualHosts configuration - only partially working

Postby mike_300zx » 05. February 2017 13:44

Hallo. I have XAMPP installed with 2 joomla sites. This is for local tests and dev. I have it working with localhost/siteone and localhost/sitetwo but I can't get the siteone.org and sitetwo.co.uk to work using Virtual Hosts. Here is what I have done.
In WinHosts:
127.0.0.1 siteone.org www.siteone.org
127.0.0.1 sitetwo.co.uk www.sitetwo.co.uk

in httpd.conf (opened from XAMPP Control Panel v3.2.2 Config button)
Listen 80 (was already there)
Listen 8080 (I added this)

In C:/xampp/apache/conf/extra/httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/siteone"
ServerName www.siteone.org
ServerAlias siteone.org
</VirtualHost>

<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/sitetwo"
ServerName www.sitetwo.co.uk
ServerAlias sitetwo.co.uk
</VirtualHost>

the syntax check with httpd.exe --t gives Syntax OK. And when I use NameVirtualHost *:80 which I saw in some earlier instructions, it says NameVirtualHost has no effect and will be removed in next ... so I commented it out again.

With the above settings, using the following urls:
localhost/siteone - works fine
localhost/sitetwo - works fine
siteone.org - gets to the correct joomla install, works fine
sitetwo.co.uk - gets to localhost dashboard

When I change the order in httpd-vhosts so the block for sitetwo.co.uk is in the file before the block for siteone.org, then I can get to the correct joomla install for sitetwo.co.uk and using siteone.org gets to localhost/dashboard.

So it looks to me that XAMPP is working ok but there is something I missed with the Apache Virtual Hosts config. Your advice will be appreciated

debug info:
XAMPP xampp-win32-5.6.28-1-VC11-installer.exe
full
Windows 10 Pro 64bit
C:\xampp\
no script
config changes as above

I can provide the log files as required.

Thanks, MIke
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby Altrea » 05. February 2017 14:20

Why has sitetwo a different port?
You want to use namebased virtual hosts, you don't need to seperate ports.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8963
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: VirtualHosts configuration - only partially working

Postby Nobbie » 05. February 2017 16:02

mike_300zx wrote:With the above settings, using the following urls:
localhost/siteone - works fine
localhost/sitetwo - works fine
siteone.org - gets to the correct joomla install, works fine
sitetwo.co.uk - gets to localhost dashboard

When I change the order in httpd-vhosts so the block for sitetwo.co.uk is in the file before the block for siteone.org, then I can get to the correct joomla install for sitetwo.co.uk and using siteone.org gets to localhost/dashboard.


Yes, its all ok. You have a wrong understanding of URLs and Hosts. If you enter http://sitetwo.co.ok into your browser, a request to the IP 127.0.0.1 on Port 80(!!!!) is issued. As you did not specify any VirtualHost for sitetwo.co.ok on Port 80 (strangely, you defined a VirtualHost for Port 8080, but your URL does not yield to Port 8080, it yields to Port 80), Apache decides to take the FIRST VirtualHost definition of your configuration (even if it does not match). Depending on which VirtualHost is first (you changed it for test reasons), Apache behave once so and once so.

Your problem is, that you specified different Ports for the VirtualHosts, but you dont apply these in your URL and you dont need these, even more, they destroy your setup. Altrea already asked you, why did you do that?
Nobbie
 
Posts: 9764
Joined: 09. March 2008 13:04

Re: VirtualHosts configuration - only partially working

Postby mike_300zx » 13. February 2017 13:18

I used different ports because I tried over 2 or 3 days to get named virtual hosts working and failed. After a lot of searching, I found a site which gave examples of needing to use Listen 8080 etc for each named vhost (I would post it here but I lost it again).
However, having read both your posts (thanks) I did the following:

in httpd.conf (opened from XAMPP Control Panel v3.2.2 Config button)
Listen 80 (was already there)
> deleted this line: Listen 8080 (I added this)

In C:/xampp/apache/conf/extra/httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/siteone"
ServerName www.siteone.org
ServerAlias siteone.org
</VirtualHost>

> changed this line from 8080 to 80 <VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/sitetwo"
ServerName www.sitetwo.co.uk
ServerAlias sitetwo.co.uk
</VirtualHost>

And now it works! That is on my local machine, I can use siteone.org and sitetwo.co.uk and get to the right instance both times. I have no idea why the same setup did not work before (which is what led me to the site that told me to use Listen ports).

Thanks, Mike
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby Altrea » 13. February 2017 13:35

Just one future improvement:
Never nest a vhost into another vhost,

so siteone and sitetwo should be outside of the htdocs folder, like so:

DocumentRoot "C:/xampp/vhosts/siteone"

and

DocumentRoot "C:/xampp/vhosts/sitetwo"
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8963
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: VirtualHosts configuration - only partially working

Postby mike_300zx » 13. February 2017 15:12

Thanks. I'll do that when I reinstall after I've upgraded XAMPP (because https://community.apachefriends.org/f/viewtopic.php?f=16&t=75302 ) I hope that thread has the right procedure.
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby mike_300zx » 03. April 2017 08:45

Altrea wrote:Just one future improvement:
Never nest a vhost into another vhost,

so siteone and sitetwo should be outside of the htdocs folder, like so:

DocumentRoot "C:/xampp/vhosts/siteone"

and

DocumentRoot "C:/xampp/vhosts/sitetwo"

OK, I found some time to carry on this project. I find that if I use
DocumentRoot "C:/xampp/vhosts/siteone"
DocumentRoot "C:/xampp/vhosts/sitetwo"

I get Access forbidden. You don't have permission to access the requested directory ... Error 403
Whereas if I use

DocumentRoot "C:/xampp/htdocs/vhosts/siteone"
DocumentRoot "C:/xampp/htdocs/vhosts/sitetwo"

I can access the Joomla install for each site.
I'm not sure if I misunderstood your advice or if I missed a step. Would be grateful for suggestions. Thanks.
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby Nobbie » 03. April 2017 10:42

Normally there is no difference between slash and backslash as Directory Divider on WIndows, anyway I am finding it ugly to mix them in a single path. Look into the access_log and into the error_log for more information, probably Joomla does some rewritingor simliar in .htaccess (or even in the PHP Code) which might fail in one case but not in the other case.

Anyway, this has nothing to do with the issue of this thread and neither with Altreas advice, which you might get wrong. Unfortunately Altrea also uses mixed slashes and backslashes in his example, but that was not the goal of the example.

P.S.: Forget the above message - i overlooked that you also applied totally different pathnames, there is missing the "htdocs" part in the first case. You probably did not apply proper rights to these DocumentRoots (i.e. you did not specify the proper "Require ...." clause). Compare the configurations carefully and go for some tutorials, it exceeds the scope of this forum to show how to configure Apache.
Nobbie
 
Posts: 9764
Joined: 09. March 2008 13:04

Re: VirtualHosts configuration - only partially working

Postby Altrea » 03. April 2017 19:53

Nobbie wrote:Normally there is no difference between slash and backslash as Directory Divider on WIndows, anyway I am finding it ugly to mix them in a single path.

I always use forward slashes in Apache configurations files, i don't mix them.

Nobbie wrote:Compare the configurations carefully and go for some tutorials, it exceeds the scope of this forum to show how to configure Apache.

Or... simply copy the configuration already given for the htdocs directory.
I always use the following template to define a vhost:

Code: Select all
# foo.dev vhost
<VirtualHost *:80>
    Servername foo.dev
    DocumentRoot "C:/xampp/vhosts/foo.dev/htdocs"
    ErrorLog "logs/foo.dev-error.log"
    CustomLog "logs/foo.dev-access.log" common
    <Directory "C:/xampp/vhosts/foo.dev/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8963
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: VirtualHosts configuration - only partially working

Postby mike_300zx » 04. April 2017 09:54

Altrea wrote:Or... simply copy the configuration already given for the htdocs directory.
I always use the following template to define a vhost:

Code: Select all
# foo.dev vhost
<VirtualHost *:80>
    Servername foo.dev
    DocumentRoot "C:/xampp/vhosts/foo.dev/htdocs"
    ErrorLog "logs/foo.dev-error.log"
    CustomLog "logs/foo.dev-access.log" common
    <Directory "C:/xampp/vhosts/foo.dev/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Thank you for your patience and kind advice. I know I am inexperienced but if you don't ask questions, you'll never learn.

Thank you also for your template. I confirm the lines inside the Directory tags work and have solved the issue. (I had found a reference to them here http://stackoverflow.com/questions/27754367/how-to-set-up-apache-virtual-hosts-on-xampp-windows as well but your template is more complete).

Just one last question if I may. Originally, you suggested
DocumentRoot "C:/xampp/vhosts/siteone"
DocumentRoot "C:/xampp/vhosts/sitetwo"

But your template implies:
DocumentRoot "C:/xampp/vhosts/siteone/htdocs"
DocumentRoot "C:/xampp/vhosts/sitetwo/htdocs"
which makes sense because (if I have it right) htdocs is where webcontent should go and I should install joomla into the htdocs folder for each site. Is that right?

Thanks again
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby Nobbie » 04. April 2017 11:27

mike_300zx wrote:but if you don't ask questions, you'll never learn.


I definately do not agree, there is plenty of documentation about Apache configuration and you should read it. Instead you ask again and again. i did not ask anybody when i learned all this stuff ((and of course i have been a "newbie" like anyone else). Its just vice verse, if you always ask instead of reading, you will never learn it, as you always get proper solutions and use them, without understanding the ideas and concepts behind that. As more you read on yourself and as more you fix problems on yourself, as more you are getting "an expert" and as more you are getting independently from forums. If you keep asking instead, you will quickly forget everything and you will ask again, when the problem occurs again. ANd you have to learn to understand error messages and what they are telling you. You are getting an Error 403 as you meantioned above - what exactly is the meaning of that error? Can you explain that? And when you see that "template" - did you work it out? Do you see "AllowOverride All"? What exactly does that mean?

Last not least, there is no general suggestion to use "htdocs" folder in order to put your HTML files there. Neither Apache nor Joomla "needs" an htdocs folder, its only a name and there are many environments which (for example) put the files into a "www" folder or into a "html" folder or or or. Even "public_html" is used in some cases. Xampp comes with a preconfigured folder "htdocs" (but for example phpmyadmin is NOT installed to htdocs) and thats all.
Nobbie
 
Posts: 9764
Joined: 09. March 2008 13:04

Re: VirtualHosts configuration - only partially working

Postby Altrea » 04. April 2017 12:42

mike_300zx wrote:Originally, you suggested
DocumentRoot "C:/xampp/vhosts/siteone"
DocumentRoot "C:/xampp/vhosts/sitetwo"

But your template implies:
DocumentRoot "C:/xampp/vhosts/siteone/htdocs"
DocumentRoot "C:/xampp/vhosts/sitetwo/htdocs"
which makes sense because (if I have it right) htdocs is where webcontent should go and I should install joomla into the htdocs folder for each site. Is that right?

It is only a recommandation. You can use any folder as DocumentRoot as you want to. It does not need to have htdocs in its name.
But on my systems i like to have a place for each vhost which is not requestable by any url. Some webapplications highly recommend to place some files outside the DocumentRoot for security reasons.
I also place some admin files there like documentations, sql templates, etc.)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8963
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: VirtualHosts configuration - only partially working

Postby mike_300zx » 04. April 2017 13:36

Altrea wrote:It is only a recommandation. You can use any folder as DocumentRoot as you want to. It does not need to have htdocs in its name.
But on my systems i like to have a place for each vhost which is not requestable by any url. Some webapplications highly recommend to place some files outside the DocumentRoot for security reasons.
I also place some admin files there like documentations, sql templates, etc.)


Yes, got it thanks. And thanks for the explanations also. That makes sense. As I research, read and learn - as well as ask questions - I found https://docs.joomla.org/Configuring_a_XAMPP_server_for_joomla_development "By convention, all web content goes under the "htdocs" folder" so that is consistent with your advice.

Until I know enough to go "off piste", I like to stick with recommendations and convention :)

You've been most helpful, thank you.
mike_300zx
 
Posts: 9
Joined: 05. February 2017 12:30
XAMPP version: for Win 5.6.28
Operating System: Windows 10 Pro

Re: VirtualHosts configuration - only partially working

Postby Altrea » 04. April 2017 15:18

You are welcome 8)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8963
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: Nobbie and 33 guests