vhost on server with dynamic ip

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

vhost on server with dynamic ip

Postby LooseCannon » 30. October 2007 18:23

I've found it a breeze setting up virtual hosts when the server has a fixed ip address. However, one laptop that needs configuring has a dynamic ip and I'd rather it stay that way. With this dynamic ip, I get served the XAMPP introduction page, being also at localhost and not the desired web page.

Extract from the vhost conf file:
Code: Select all
<VirtualHost *:80>
  ServerName myDomain.local
  ServerAlias www.myDomain.local
  DocumentRoot C:/xampp/myDomain/htdocs
  DirectoryIndex default.php
</VirtualHost>

<Directory "C:/xampp/myDomain/htdocs/">
  Options Indexes FollowSymLinks Includes MultiViews
  AllowOverride All
  Order Allow,Deny
  Allow from All
</Directory>


Extract from the laptop's host file:
Code: Select all
127.0.0.1   localhost
127.0.0.1   myDomain.local


Launch link:
Code: Select all
http://myDomain.local/


If I change to the current actual ip <VirtualHost 50.100.150.107:80>, it works, ie I get served with c:/xampp/myDomain/htdocs/default.php.

It's gotta be a dumb typo or error on my part. I've spent hours searching the fora and trying different permutations. Any ideas or suggestions would be appreciated. Thanks.

EDIT: Blimey, my first post! Thought I'd got involved before now, but clearly not. Hello all. o/
EDIT2: bleh...
EDIT3: Patch up after EDIT2... get a strong coffee...
Last edited by LooseCannon on 31. October 2007 10:34, edited 4 times in total.
User avatar
LooseCannon
 
Posts: 162
Joined: 18. September 2007 12:07
Location: Hampshire, UK

Postby Izzy » 30. October 2007 22:42

Try replacing your entries (they are not quite right, old chap) ;) with this code after all the commented text in your http-vhosts.conf file and make sure there is no uncommented entry above this code:
Code: Select all
<VirtualHost 127.0.0.1:80>
ServerName localhost
DocumentRoot "C:/xampp/mydomain/htdocs"
<Directory "C:/xampp/mydomain/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

NameVirtualHost *:80

<VirtualHost *:80>
ServerName myDomain.local
ServerAlias www.myDomain.local
ServerAdmin serveradmin@myDomain.local
DocumentRoot "C:/xampp/myDomain/htdocs"
<Directory "C:/xampp/myDomain/htdocs" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "C:/xampp/myDomain/htdocs/cgi-bin/"
</VirtualHost>

Make sure this path "C:/xampp/mydomain/htdocs" is your DocumentRoot in the xampp\apache\conf\httpd.conf file, like this:
DocumentRoot "C:/xampp/mydomain/htdocs"

Restart Apache after making any changes in any conf or ini file and always make a backup of the originals before editing.

You can carry on adding more domains in much the same way after the last entry above by copy and pasting the complete <VirtualHost></VirtualHost> container and then changing the domain name and the directory paths etc. to suit - leave a 2 line gap between each <VirtualHost></VirtualHost> container is the norm.

You may use the command apache -S at a command prompt opened in the xampp\apache\bin directory to verify your virtual host configuration file syntax and display any errors that might be evident.
HTH


===========================================
1. The new DeskTopXampp launch control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Make Richer Ajax Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Conflist remains: localhost - XAMPP - myDomain &dynamic

Postby LooseCannon » 31. October 2007 11:52

Thanks Izzy. V nice feedback,,, as always.

How did you know I'm not quite right?! Oh, you mean the code... :P

I note that you nest <Directory .. </Directory> within <VirtualHost .. , when I've put it after. Otherwise, I think I follow everything you've put in there.

I did as you suggested, this way:
1. Commented out everything in the current vhost conf;
2. Copy/pasted your vhost/dir entries at the bottom of that file;
3. Replaced myDomain with the real name;
4. Checked _again_ that the ream name and document roots are typed correctly. NB: vhost works when use an ip, so the paths should be correct;
5. Started apache & mysql, as it wasn't running to start with today;
6. IE - http:\\myDomain.local - bingo: myDomain appears (though without the php error that _should_ appear due to a variable not being set!@$%?);
7. XAMPP - admin - bongo: myDomain appears instead of the XAMPP welcome page.

So, we have the conflict I've faced before between localhost and XAMPP.

Your code duplicates the myDomain info instead of catching XAMPP? You refer to DocumentRoot in the _main_ xampp\apache\conf\httpd.conf file pointing to C:/xampp/mydomain/htdocs", but this is set in the vhost conf, not the main web server config?

Let's check the apache config:
Code: Select all
C:\Documents and Settings\Administrator>C:\xampp\apache\bin\apache -S
VirtualHost configuration:
127.0.0.1:80           localhost (C:/xampp/apache/conf/extra/httpd-vhosts.conf:61) wildcard NameVirtualHosts and _default_ servers: _default_:443
      localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:74) *:80 is a NameVirtualHost
        default server myDomain.local (C:/xampp/apache/conf/extra/httpd-vhost
s.conf:73)
        port 80 namevhost myDomain.local (C:/xampp/apache/conf/extra/httpd-vhosts.conf:73)
Syntax OK


This seems to refer to a conflict with the default and vhost, but I don't find this informative.

So, I tweaked your code and made the first section refer to XAMPP:
Code: Select all
<VirtualHost 127.0.0.1:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This makes the XAMPP welcome screen appear, but also for http://myDomain.local. No suprise because my Window's host file says "127.0.0.1 myDomain.local". I rem that out and XAMPP welcome still works ok, but http://myDomain.local takes me _online_ to a valid web site "local.co.uk". I change ServerName in the vhost config from myDomain.local to "yeeharr.banana" (seriously... well, ok not as in 'seriously') and IE cannot display the web page. I'll not mention the several occasions when I forgot to restart apache.....

Another hour of 'oh, I'll just try that or this or the other ...' and no luck.

My main queries are:
a. How does 127.0.0.1:80 localhost differ from *:80 myDomain.local, and require two vhost configs?
b. What effect and/or changes should be made to the _main_ apache config DocumentRoot? I thought none were necessary for vhost config, but I've not faced a dynamic ip before.
c. Should I just give up on the XAMPP welcome page/site and make myDomain the localhost'ed site and link directly to phpMyAdmin for database updating? Being quite new to XAMPP, I know not what I might miss from that page.

/me sups on a camomile tea...
User avatar
LooseCannon
 
Posts: 162
Joined: 18. September 2007 12:07
Location: Hampshire, UK

Postby Izzy » 01. November 2007 04:13

LooseCannon wrote:Thanks Izzy. V nice feedback,,, as always.

Thanks and your welcome - for some I have to 'cross the Is and dot the Ts' or is that 'cross Ts and dot the Is'? :)

LooseCannon wrote:/me sups on a camomile tea...

That chamomile stuff is for external use to stop itchy spots and, but irrelevant for those in the UK ;) , sunburn! - try a real cupa (or is it cuppa?) for internal use (more caffeine that helps you stay up at night 'dotting the Ts and crossing the Is', oops!) :D

Anyhow back to the drawing board - you can change this:
Code: Select all
<VirtualHost 127.0.0.1:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

NameVirtualHost *:80

<VirtualHost *:80>
ServerName myDomain.local
ServerAlias www.myDomain.local
ServerAdmin serveradmin@myDomain.local
DocumentRoot "C:/xampp/myDomain/htdocs"
<Directory "C:/xampp/myDomain/htdocs" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "C:/xampp/myDomain/htdocs/cgi-bin/"
</VirtualHost>

to this and try it again to see if it works:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName myDomain.local
ServerAlias www.myDomain.local
ServerAdmin serveradmin@myDomain.local
DocumentRoot "C:/xampp/myDomain/htdocs"
<Directory "C:/xampp/myDomain/htdocs" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "C:/xampp/myDomain/htdocs/cgi-bin/"
</VirtualHost>

These previous posts may be of help for you - the second is in German but the relevant part is not and in my browser, SeaMonkey, I can select from the Tools menu to Translate the page, which is performed by Google - not perfect but understandable-ish. ;)
http://community.apachefriends.org/f/viewtopic.php?t=22826
http://community.apachefriends.org/f/viewtopi ... host#34538

Also a search on these English forums for vhost or virtualhost will give you many results, as it is a very popular subject indeed.

I take it that this was a typo?
6. IE - http:\\myDomain.local - bingo:


Return your host file to include the 127.0.0.1 mydomain.local entry and also add any more entries for domains you want to access locally.

Try and access XAMPP by using a URL before using the Admin... button in the control panel.
http://localhost/
or
http://127.0.0.1/


Now in answer to your questions:

a.
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
http://httpd.apache.org/docs/2.2/mod/co ... irtualhost
http://httpd.apache.org/docs/2.3/vhosts/examples.html

All the directives are here:
http://httpd.apache.org/docs/2.2/mod/directives.html


b.
I asked you to check this was correct because usually it is, as you say
DocumentRoot "C:/xampp/htdocs"
but I had no way of knowing so I included in the localhost container the only one I knew you had.
(Sorry I should have dotted the T, oops!). ;)


c.
I was assuming that http://myDomain.local was a fully qualified domain name (FQDN) registered with a domain name registrar (GoDaddy etc.) and with nameservers from the likes of ZoneEdit etc. for your dynamic IP (after you tell the nameservers each time it changes) to know where to find your site and therefore accessible from the Internet - you did say you had a external dynamic IP which is totally irrelevant at the internal local level.

http://community.apachefriends.org/f/viewtopi ... 792#109792

If not and this is your only site, other than XAMPP, accessible locally, then there is no need of a vhost container and you should revert the vhost conf file to the default.

You then delete the index.php in the htdocs directory and place your site's index file and the rest of the site's files and directories in there so that
http://localhost/
will now show you your site and
http://localhost/xampp
will show the XAMPP Welcome Page.

If it had been a FQDN then the vhost configuration above would have worked instead of going to the local.co.uk link directory site.

What happened is this - if you are connected to the Internet via your ISP and you type an address http://myDomain.local in your address bar then the browser sends that off to your ISP's Domain Name Servers to find the address where to send it.

If it can't find that address in it's DNS database then it sends it either to a domain that is registered to receive mis-spelled or similar domain names, like it did to local.co.uk, or it returns an unknown address error to your browser, like it did with your BannanaArmy :) address - I am sure you will have seen a few of these and also ended up at sites like local.uk.co after typing in a different URL in your browser.

If someone else, not on your local network uses your http://myDomain.local and you have it registered like I mentioned above and you have your server running then they will see your site, as Apache, via the vhost conf file, knows where to look for it and can distinguish it from the localhost (XAMPP) site and so will serve your site to the visitor.


Sorry for the book length post again but I have this irresistibly urge to 'cross the Is and dot the ts' - oops! again, damn it. :)


Some members here might post a suggestion that using an XAMPP loader/launcher might make all this, life and everything much easier but IMHO. knowing the intricacies of a web server and it's configuration files is really what this webmaster game is all about, don't you think?
Anyhow, I HTH.


===========================================
1. The new DeskTopXampp launch control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Make Richer Ajax Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby LooseCannon » 01. November 2007 11:46

I was tempted to post a 1 liner, just to balance out the thread a little. :lol:

Izzy wrote:...

Sorry for the book length post again but I have this irresistibly urge to 'cross the Is and dot the ts' - oops! again, damn it. :)
A well crossed and dotted thread can help many folks. That's fora at their best imo, so keep it up!

Izzy wrote:Some members here might post a suggestion that using an XAMPP loader/launcher might make all this, life and everything much easier but IMHO. knowing the intricacies of a web server and it's configuration files is really what this webmaster game is all about, don't you think?
Anyhow, I HTH.
Understood and agreed. This type of experimentation and the learning in engenders works very well for me and I guess many others.

Now,,, back to trying your suggests Izzy. I've already tried something that looked like your vhost suggest no.2 above.

Btw, this is _not_ a fqdn, but I believe just utilising the default c:\xampp\htdocs path/location isn't what I'm looking for. Leave it with me. I'm also looking to install in an encrypted volume, so that's not "c:\.." which is another issue looming for the defaults,,, and _another_ likely thread.

Oh and "6. IE - http:\\myDomain.local - bingo:" _was_ a typo. I started computing pre-DOS and still get confused. :oops:

/me has a strong coffee otw! :)
User avatar
LooseCannon
 
Posts: 162
Joined: 18. September 2007 12:07
Location: Hampshire, UK

Resolved! Izzy for President

Postby LooseCannon » 02. November 2007 10:10

Got it working as I planned/hoped. 8)

Summary:
1. Server = laptop with dynamic ip
2. Non-FQDN, used only on this laptop, which I've renamed here to "myDomain.local"
3. Local access only
4. c:\WINDOWS\system32\drivers\etc\hosts file has the line: 127.0.0.1 myDomain.local
5. u:\xampp\apache\conf\extra\httpd-vhost.conf file is all commented (# at start of line) except:
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "u:/xampp/htdocs"
<Directory "u:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName myDomain.local
ServerAlias www.myDomain.local
ServerAdmin thereisnoadmin@myDomain.local
DocumentRoot "u:/xampp/myDomain/htdocs"
DirectoryIndex default.php
<Directory "u:/xampp/myDomain/htdocs" >
Options Indexes FollowSymLinks Includes MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "u:/xampp/gigatronix/htdocs/cgi-bin/"
</VirtualHost>

5a. Note that I added a DirectoryIndex line and the Multiviews option to the code suggested by Izzy
6. Local html and php files for myDomain.local stored at u:/xampp/myDomain/htdocs
7. XAMPP welcome and phpMyAdmin web sites neither moved nor affected, and still both functioning indepenently of myDomain.local functionality.

This is really very close to what I was trying before Izzy's much appreciated assistance. It shows how the text based configuration of Apache is clear to see, but simple error not so clear to spot. The links above to other threads regarding vhosts and the Apache reference material are all very helpful, but they can't read the code on your screen. :D

So, the myDomain.local site now works, installed on an encrypted volume u:\ and updatable periodically via html/php file copying and phpMyAdmin exports-imports. Nice,,, EXCEPT that I now a have problem that I've faced and dealt with 4 or 5 times this last few months, and now can't resolve. I'm sure it's relates to register_globals, but damned if I can sort it. [link to new thread to be edited in]

Thanks Izzy for the help. :tup:
User avatar
LooseCannon
 
Posts: 162
Joined: 18. September 2007 12:07
Location: Hampshire, UK

Postby Izzy » 02. November 2007 10:53

Great news, I do like it when things come together and a rare 1 liner from me. :)


===========================================
1. The new DeskTopXampp launch control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Make Richer Ajax Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby cheeto4493 » 12. November 2007 05:13

Thanks, you 2 helped me out without knowing it. I've been banging my head on this all afternoon. Finally got it.

I have 3 domains set up

localhost = goes to xampp control panel -> default vhost domain
mycomputer -> htdocs/myfolders
myDomain.local -> test website.

Is there a way to access the myDomain via local LAN short of changing the port numbers or default Vhost? I don't think there is, but was wondering if I overlooked something.

I can enter my computer IP and it takes me straight to the xampp panel
cheeto4493
 
Posts: 5
Joined: 12. November 2007 05:03

Postby Izzy » 12. November 2007 05:50

I am pleased to see that a forum search worked for you. :)

You can add your lan IP to the Windows hosts file to point to mydomain.

For example
127.0.0.1 localhost
127.0.0.1 mydomain.local
127.0.0.1 mydomain
192.168.0.20 mydomain.local
192.168.0.20 mydomain

Any entry that relates to localhost 127.0.0.1 is only accessible by your PC.

Any other entries can be accessible from the lan if you so desire.

This link might help explain better than I can.
Step-by-Step: How to write a HOSTS file


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby cheeto4493 » 13. November 2007 17:18

I think get it now.

When I type my IP address in the address bar on another computer on the LAN I get the default domain.

by putting my IP address in the hosts file on another computer on the LAN
192.168.0.19 myDomain.local

The computer still finds my server on the same IP and port, BUT the domain name is passed in the header and by way of Vhosts gets rerouted to the right domain....

The only down side is that the entry has to be put in every hosts file on each computer on the LAN that wants access. OR.....

If I can get the IT guy to put it in the DNS entry on the local Network Server, it should work the same as the hosts file?
cheeto4493
 
Posts: 5
Joined: 12. November 2007 05:03

Postby LooseCannon » 13. November 2007 17:58

Very glad to assist.

Yes, the host file solution needs to be done in each PC. Also, maybe sometime, it has to me un-done. Forgetting that can be fun.

cheeto4493 wrote:... If I can get the IT guy to put it in the DNS entry on the local Network Server, it should work the same as the hosts file?

You think you can actually _find_ the IT guy _and_ he'll help?!? :shock: :wink:

Note that the PC's would have to be looking at that DNS server. Yes, I'm a unskilled and careless IT guy, so I bet my network PCs point to all sorts of DNS servers. Maybe they should all point to the Domain Controller and that forwards DNS queries to itself, then maybe your ISP etc.

However, my network has too much 'history'. I hope your guy's tidier and more methodical than me. :P

Out of interest cheeto4493, how many PC's are you looking at for this?
User avatar
LooseCannon
 
Posts: 162
Joined: 18. September 2007 12:07
Location: Hampshire, UK

Postby cheeto4493 » 13. November 2007 19:12

I'm at a church with about 15 machines. The IT guy is available, and somewhat willing, If I had a good reason.

Right now, I am just playing, and learning. But it might come in handy if we decide to host our own website instead of using a hosting company. I like building websites with PHP, but the downside is you need a server set up to preview the page. Sometimes I like to go around to a different machine and see how it looks with different version browsers and different screen sizes.

What would be cool is if someone came up with a "Webmaster Browser" that had all of the different browser engines built in, and you just check the one you want to test. I use FireFox, and really like the "Web Developer Toolbar"

I think our router is set up to direct DNS stuff to the local server before going out to the internet. I think this is set up for Outlook Server, which we have never used. I usually forget about it until the server goes down, and then we have issues with no DNS server found.
cheeto4493
 
Posts: 5
Joined: 12. November 2007 05:03


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 147 guests