Apache error when trying to use virtual hosts

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

Apache error when trying to use virtual hosts

Postby pcs800 » 04. February 2011 02:46

I have a web server running apache and php5 installed by xampp, since 2006 it has been running a single web site without issue. Now we want to add a second so here's what I did.

Added the following to the httpd-vhosts.conf file
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName www.site1.com
DocumentRoot “C:/xampp/htdocs/site1folder”
ErrorLog “C:/xampp/htdocs/site1folder/errorlog”
DirectoryIndex index.html index.php index.html
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName www.site2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/errorlog”
DirectoryIndex index.html index.php index.html
</VirtualHost>

Then I uncommented this line within httpd.conf
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"

When I restarted apache I got this:
The Apache service named reported the following error:
>>> [Thu Feb 03 17:29:42 2011] [warn] module php5_module is already loaded, skipping

and apache would not start.

I checked for two instances of LoadModule php5_module, which there is not.
Soooo, why when I enable virtual hosts does php5 try to load twice?
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby JonB » 04. February 2011 03:20

I'm not too sure why Apache isn't starting, I don't 'tihnk' its because of the php5 thing, that's a warning. What else is in the Apache error log???

Another question would be - have you loaded any PHP scripts into those new virtuals hosts?.

As an aside - normally, the first VirtualHost is the 'default host' (usually \xampp\htdocs) where anything that fails on name resolution will land.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Apache error when trying to use virtual hosts

Postby Sharley » 04. February 2011 03:25

Your error was not an error but merely a [warn]ing.

Did you spot this in your \xampp\apache\logs\error.log file as this is the best place for clues when Apache can't start and was the above the only entry or did you see any [error] entries?

pcs800 wrote:Added the following to the httpd-vhosts.conf file
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName http://www.site1.com
DocumentRoot “C:/xampp/htdocs/site1folder”
ErrorLog “C:/xampp/htdocs/site1folder/errorlog”
DirectoryIndex index.html index.php index.html
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName http://www.site2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/errorlog”
DirectoryIndex index.html index.php index.html
</VirtualHost>
Try this by copy and paste over your existing entries
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot “C:/xampp/htdocs/site1folder”
ErrorLog “C:/xampp/htdocs/site1folder/error.log”
DirectoryIndex index.html index.php index.htm
</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
ServerAlias www.sire2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/error.log”
DirectoryIndex index.html index.php index.htm
</VirtualHost>
Save the file and restart Apache (if you can). ;)

Also add this to your C:\Windows\system32\drivers\etc\hosts file by dragging it into your text editor - make sure they are the first 3 entries like so
Code: Select all
127.0.0.1 localhost
127.0.0.1 site1.com
127.0.0.1 site2.com
Save the file and make sure your text editor does not add the .txt extension or it will break it.

Try the above and see if the error goes away and Apache can start.

Best wishes. :)
Last edited by Sharley on 06. February 2011 02:41, edited 2 times in total.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 04. February 2011 03:36

The original "site1" has always ran in C:/xampp/htdocs/site1folder never just C:/xampp/htdocs
The hosts file already has entries for site1 but not 127.0.0.1 but the actual ip address of the server. Is this an issue? It's worked for years like that.
I did add x.x.x.x site2.com though.

To answer Jonb's question, there may be some script which is part of site1 that calls php but again, it has always worked.
If I comment out LoadModule php5_module in the httpd.conf file, then that would disable php completely wouldn't it?
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby Sharley » 04. February 2011 03:41

You have only had one vhost before which incidentally was also setup incorrectly.

In the code entry above is the correct method to configure the httpd-vhost.conf file obtained from the Apache manual - worth reading.

The first entry is the default localhost entry and must be included before your site1 and site2 vhosts.

Try my code and see what happens - you have nothing to loose and everything to gain.

This post may help:
viewtopic.php?p=169750#p169750

Best wishes.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 04. February 2011 03:49

I cannot get to that server at this moment, but will try your code tomorrow.
As added info, we have never had the virtual host uncommented in the httpd.conf file, so no virtual host was ever used.
xampp was simply told that the web site on this server exists at htdocs/site1
Additionally, I did not set it up so it's harder for me to go through and figure all this out. I appreciate the responses.
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby Sharley » 04. February 2011 04:11

pcs800 wrote:The hosts file already has entries for site1 but not 127.0.0.1 but the actual ip address of the server. Is this an issue? It's worked for years like that.
I did add x.x.x.x site2.com though.
No, this is correct but if you want to access from the machine that XAMPP is installed on then it won't hurt to also add the 127.0.0.1 local loop back addresses as well.

BTW, you can't, as you say, comment out the php5 module for the reason you posted.

This *:80 in the vhost means that Apache will listen for any IP on port 80 and so is referred to as an IP wild card and will work for your server IP as well as the local loop back IP.

Best wishes.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 04. February 2011 04:29

So how about if I use your code like this.

NameVirtualHost *:80

<VirtualHost *:80
ServerName localhost
DocumentRoot "C:/xampp/htdocs/site1folder">
</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/error.log”
DirectoryIndex index.html index.php index.htm
</VirtualHost>
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby Sharley » 04. February 2011 04:44

pcs800 wrote:So how about if I use your code like this.

NameVirtualHost *:80

<VirtualHost *:80
ServerName localhost
DocumentRoot "C:/xampp/htdocs/site1folder">
</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
ServerAlias http://www.site2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/error.log”
DirectoryIndex index.html index.php index.htm
</VirtualHost>
You can of course try that if you like but read the error.log file if Apache can't start and paste any error entries you find at about the time and date you try the above.

In my code above http://localhost will go to the C:/xampp/htdocs/xampp folder if accessing from the PC that XAMPP is installed on by default and will show the XAMPP Welcome Demo page which will indicate that your vhost file is not configured correctly.

You can access your sites also from the PC that XAMPP is installed on as well:
http://localhost/site1 will go to your site1 site
http://localhost/site2 will go to your site2 site.
as will
http://127.0.0.1/site1
and http://127.0.0.1/site2

Others using your server IP can also access your sites but not using the localhost address.
They must use the server IP address.
http://xxx.xxx.xxx.xxx/site1 will go to your site1 site
http://xxx.xxx.xxx.xxx/site2 will go to your site2 site

Thats how my code above will work for you.

Best wishes.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 05. February 2011 19:47

Ok I put your code in the file and I got an error when starting apache., actually 3 entries in the event viewer.
Here they are top to bottom..

The Apache service named reported the following error:
>>> <VirtualHost> directive missing closing '>'
--
The Apache service named reported the following error:
>>> Syntax error on line 46 of C:/xampp/apache/conf/extra/httpd-vhosts.conf:
--
The Apache service named reported the following error:
>>> [Sat Feb 05 10:38:41 2011] [warn] module php5_module is already loaded, skipping
--

The error.log doesn't get put in the specified folder either.
It is in C:\xampp\apache\logs
--
in httpd.conf, I had not even uncommented this line yet
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"


Any ideas?
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 05. February 2011 19:57

For the syntax error on line 46, it was this.

<VirtualHost *:80
which needed to be this
<VirtualHost *:80>

So now I get a syntax error on line 48 which is this line.
DocumentRoot "C:/xampp/htdocs">
It appears the code has errors all through it?
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby WilliL » 05. February 2011 20:34

change
DocumentRoot "C:/xampp/htdocs">
to
DocumentRoot "C:/xampp/htdocs"

http://httpd.apache.org/docs/2.0/en/vhosts/name-based.html
Willi
WilliL
 
Posts: 660
Joined: 08. January 2010 10:54
Operating System: Win7Home Prem 64 SP1

Re: Apache error when trying to use virtual hosts

Postby Sharley » 06. February 2011 02:44

pcs800 wrote:So how about if I use your code like this.

NameVirtualHost *:80

<VirtualHost *:80
ServerName localhost
DocumentRoot "C:/xampp/htdocs/site1folder">
</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
ServerAlias http://www.site2.com
DocumentRoot “C:/xampp/htdocs/site2folder”
ErrorLog “C:/xampp/htdocs/site2folder/error.log”
DirectoryIndex index.html index.php index.htm
</VirtualHost>

The code I posted has been corrected and now has no typos as you can see:
viewtopic.php?p=173483#p173483

The error.log doesn't get put in the specified folder either.
It is in C:\xampp\apache\logs
This the default location for the error.log file and will be used when there are errors in your httpd-vhost.conf file.
pcs800 wrote:in httpd.conf, I had not even uncommented this line yet
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
The red relevant line in the httpd.conf file is uncommented already by default, so nothing to do there.


BTW this is a warning not an error
Code: Select all
>>> [Sat Feb 05 10:38:41 2011] [warn] module php5_module is already loaded, skipping
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Apache error when trying to use virtual hosts

Postby pcs800 » 13. February 2011 22:35

Ok with the new code (without typos) I do not get the error messages but apache won't start when I put the code into the httpd-vhosts.conf file.
The only thing that shows in event viewer is the warning
module php5_module is already loaded, skipping
But that seems to also show when I revert httpd-vhosts.conf to it's original state and apache does start. So it isn't the cause I suppose.
Would the error number that shows when I get "Apache has terminated unexpectedly" help?
pcs800
 
Posts: 33
Joined: 22. September 2005 15:08

Re: Apache error when trying to use virtual hosts

Postby Sharley » 14. February 2011 01:25

If Apache can't start the best place for more detailed clues is the \xampp\apache\logs\error.log file.

Also you could issue, at a command prompt in the \xampp\apache\bin folder, this command to check the syntax of your httpd-vhosts.conf file:
Code: Select all
apache -S
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Next

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 98 guests