Page 1 of 1

Virtual Hosts - if statment... help.

PostPosted: 22. January 2009 10:52
by evolutionxbox
Here are 2 of my virtual hosts in my 'httpd-vhosts.conf' file (they have their '127.0.0.1 localhost' in the windows hosts file).

Code: Select all
## ----------------------------------------------------------------------------
## Client: localhost
## ----------------------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/mysite"
    ServerName localhost
   <Directory "C:/mysite">
      AllowOverride None
      Order allow,deny
      Allow from all
   </Directory> 
</VirtualHost>

Code: Select all
## ----------------------------------------------------------------------------
## Client: localhost2
## ----------------------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "E:/myweb"
    ServerName localhost
   <Directory "E:/myweb">
      AllowOverride None
      Order allow,deny
      Allow from all
   </Directory> 
</VirtualHost>



The problem is that the 'E drive' (E:\) is not always available, so when it's not there Xampp doesn't run.

Is there a way to add an if statement which checks to see if the 'E drive' is available before adding that virtual host? Or some other method besides deleting the offending virtual host?

Re: Virtual Hosts - if statment... help.

PostPosted: 22. January 2009 11:27
by Izzy
The problem is that the 'E drive' (E:\) is not always available, so when it's not there Xampp doesn't run.

You have 2 servers named localhost is the other on a portable drive USB perhaps?

XAMPP should always remain the localhost by default.

You should rename the localhosts to something else and add the changed ServerNames in to the hosts file for example 127.0.0.1 changedname 127.0.0.1 changedname2

Open a command prompt in the apache\bin folder type apache -S and see what it tells you about the syntax.

Apache won't start if there is a syntax error and running apache_start.bat file will give you a detailed error message why apache won't start

I don't know of any if statement you can use in an Apache conf file but this vhost conf should do what you want.
Code: Select all
NameVirtualHost *:80

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

## ----------------------------------------------------------------------------
## Client: mysite
## ----------------------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/mysite"
    ServerName mysite
   <Directory "C:/mysite">
      AllowOverride None
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>

## ----------------------------------------------------------------------------
## Client: myweb
## ----------------------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "E:/myweb"
    ServerName myweb
   <Directory "E:/myweb">
      AllowOverride None
      Order allow,deny
      Allow from all
   </Directory>
</VirtualHost>

HOSTS file
127.0.0.1 localhost
127.0.0.1 mysite
127.0.0.1 myweb

http://localhost - will give you the XAMPP Welcome page etc.
http://mysite - will give the site in the mysite folder.
http://myweb - will give the site in the myweb folder.

Edit:
The above configuration is for a fixed E:\ drive not a USB drive.

Re: Virtual Hosts - if statment... help.

PostPosted: 23. January 2009 13:41
by evolutionxbox
Image

This is what I get (following your guidelines) when I run XAMPP without the USB Drive (E:\)... why?

I did it correctly. *sobs*

Re: Virtual Hosts - if statment... help.

PostPosted: 23. January 2009 14:42
by Izzy
Izzy wrote:You have 2 servers named localhost is the other on a portable drive USB perhaps?
I asked this question but there was no answer so I carried on as if you had a fixed E drive.

When the USB is removed the E drive is also removed from the system so to all intents and purposes the E drive or partition does not exist and the Apache server can't find the DocumentRoot in the missing E drive so it chucks a wobbly.

So as far as I know at this point it is not possible to do in a virtualhost or an Alias because they both need a fixed drive or partition recognised by the system - I have justed tested this out on one of my XAMPP installs using the Z drive which I don't have setup as a drive or a partition and received the same syntax errors and Apache chucked a wobbly.

Some one else may be able to help you but in the mean time I will investigate the issue and see if I can find a suitable solution, but I am not confident. ;)

Re: Virtual Hosts - if statment... help.

PostPosted: 23. January 2009 16:02
by evolutionxbox
Sorry, I seem to that later (missing out vital info I mean)...

Well, thanks for all your hope so far.
What I am going to do until any further progress is made is that I shall keep 2 vhosts files and change their names depending on whether the E Drive is plugged in or not (laborious I know but it is better than nothing).

Izzy wrote:...Apache chucked a wobbly.


Wobbly, lol, love it. =)