I am trying to use NameVirtualHost to allow me to serve several
websites accross an intranet. I want to do this because I need to
serve them all from the same ip address ... the ip address of the
pc on a p2p network running the apache server. Using :
Windows 98 running:
Apache 1.3.12
PHP 4.0.6
MySQL 3.23.21-beta
& windows 2000 & 98 on othe networked PC's
Up untill now I have beeen using ip-based virtual hosts and this works fine if I only want to access the domains on the one server machine, but if I want to access them all via another p2p pc I only have one ip address available (the ip address of the apache server pc on the network)
All the mysql db's are accessable if I run directly on the apache server pc if I use ip-based hosting ... so I know that mysql is setup ok.
I am using the windows Hosts file to point the domain names to the local server, so on each pc I have:
123.4.5.6 www.sitea.com
123.4.5.6 www.siteb.com
etc...
Note:
123.4.5.6 is really the ip address of the pc on the P2P network that is running the apache server.
When I switch to Name-Based virtual hosting, standard HTML & PHP pages work without problem locally and across the network.
But when I try to connect to a website that has a database e.g.:
$connection = mysql_connect("www.siteb.com", "username", "password");
I get the error:
Unable to connect to MySQL server..1045
Access denied for user: 'mydbname@sitea.com' (Using password: YES)
????? sitea ... should be siteb
It appears that mysql always tries to connect to the first site in my hosts file.
If I switch the order of the lines in the hosts file so that siteb is first then restart apache, mysql & the browser and retry I can access siteb's db correctly... but now not sitea's db!
~~~~~~~
this is the relevent apache http.conf
NameVirtualHost 123.4.5.6
#--------------------------------------------------------------------
<VirtualHost 123.4.5.6>
ServerName www.sitea.com
DocumentRoot c:/home/sitea/public_html
ScriptAlias /cgi-bin/ c:/home/sitea/cgi-bin/
ServerAdmin [email]webmaster@sitea.com[/email]
ErrorLog logs/www.sitea.com-error_log
CustomLog logs/www.sitea.com-access_log common
</VirtualHost>
#--------------------------------------------------------------------
<VirtualHost 123.4.5.6>
ServerName www.siteb.com
DocumentRoot c:/home/siteb/public_html/merlin
ScriptAlias /cgi-bin/ c:/home/siteb/cgi-bin/
ServerAdmin [email]webmaster@siteb.com[/email]
ErrorLog logs/www.siteb.com-error_log
CustomLog logs/www.siteb.com-access_log common
</VirtualHost>
etc...
Is there a fix to let mysql use name-based V.hosting?
or does this point to some other boob i've made?
or am I missing something in the network setup that will either allow me to access each domain using ip-based V.Hosting from another PC on the network ...
for ip-based I think I need to either :
setup a DNS for this
... if so do you know of any good (i.e. simple!) guides that could help?
or I could assign multiple ip addresses to the network card and
then I could attach each name to its own ip address
... this is messy as unfortunatly the server is a WIn98 PC and it requires a bit of a registry hack to assign multiple ip addresses to a network card.
Thanks (and sorry for the long posting)
Chris