Sticky for virtual hosts - aka XAMPP will not start

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

Sticky for virtual hosts - aka XAMPP will not start

Postby stevehomer » 19. May 2016 13:03

EDIT: I should have added if anyone has a link to a GOOD simple virtual hosts "How To" for Win 10 I would be very very greatful.


I have successfully got up and running with virtual hosts on about 4 machines in the past. I am damned if I can get it working here so reinstalling XAMPP for the second time.

I want to be able to use foo.dev and bar.dev and just have them as URLs mapping their roots to directories htdocs\foo.dev and htdocs\bar.dev.

I have done this before on about 5 occasions but this is the problem - I can never remember exactly how I did it (edit host in etc, httpd.conf in apache\conf and httpd-vhosts.conf in extra).

Before I started fiddling around localhost was working fine and then when I changed all these files back nothing is working.

PLEASE can we have a sticky for setting up virtual hosts. I have Googled until my eyes bleed and seen so many contradictory methods.

If there was one method here, then, if it did not work we would all start from the same point when looking for help.

TIA Steve

PS A little guidance on Winows Event Viewer would also be nice in the error message or in the current sticky. I cannot find any useful info in WEV. My log on this installation was :

12:44:12 PM [main] Initializing Control Panel
12:44:12 PM [main] Windows Version: Home 64-bit
12:44:12 PM [main] XAMPP Version: 5.6.19
12:44:12 PM [main] Control Panel Version: 3.2.2 [ Compiled: Nov 12th 2015 ]
12:44:12 PM [main] Running with Administrator rights - good!
12:44:12 PM [main] XAMPP Installation Directory: "c:\xampp\"
12:44:12 PM [main] Checking for prerequisites
12:44:12 PM [main] All prerequisites found
12:44:12 PM [main] Initializing Modules
12:44:12 PM [main] Starting Check-Timer
12:44:12 PM [main] Control Panel Ready
12:44:15 PM [Apache] Attempting to start Apache app...
12:44:15 PM [Apache] Status change detected: running
12:44:16 PM [Apache] Status change detected: stopped
12:44:16 PM [Apache] Error: Apache shutdown unexpectedly.
12:44:16 PM [Apache] This may be due to a blocked port, missing dependencies,
12:44:16 PM [Apache] improper privileges, a crash, or a shutdown by another method.
12:44:16 PM [Apache] Press the Logs button to view error logs and check
12:44:16 PM [Apache] the Windows Event Viewer for more clues
12:44:16 PM [Apache] If you need more help, copy and post this
12:44:16 PM [Apache] entire log window on the forums
stevehomer
 
Posts: 4
Joined: 19. May 2016 12:31
XAMPP version: 5.6.19
Operating System: Win 10

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby gsmith » 19. May 2016 17:18

How about Apache's error.log and if nothing else, starting Apache from the command line?
It's a misspelled directive most likely but we'll see. Anyway, here goes;

File: c:\windows\system32\drivers\ect\hosts
Add
Code: Select all
127.0.0.1     foo.dev
127.0.0.1     bar.dev

File: c:\xampp\apache\conf\httpd.conf
Take note what the DocumentRoot is in this file. You will need to know it later.
Uncomment the Include for httpd-vhosts.conf
Code: Select all
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

File: c:/xampp/apache/conf/extra/httpd-vhosts.conf
This has been working for me since Apache 1.3.0 back in 1998.
Code: Select all
# We can use "Define" in Apache 2.4 and it's surprising it is not used more
Define DOCROOT "c:/xampp/htdocs"

# The default (and first VirtualHost) must be pointed to the same DocumentRoot as the
# (global) DocumentRoot in httpd.conf

  <VirtualHost _default_:80>
      DocumentRoot "${DOCROOT}"
  </VirtualHost>

# Now you can start adding more hosts

# foo.dev
  <VirtualHost *:80>
      DocumentRoot "${DOCROOT}/foo.dev"
      ServerName foo.dev
      ServerAdmin webmaster@foo.dev
      CustomLog /logs/ foo.access.log common
  </VirtualHost>

# bar.dev
  <VirtualHost *:80>
      DocumentRoot "${DOCROOT}/bar.dev"
      ServerName bar.dev
      ServerAdmin webmaster@bar.dev
      CustomLog /logs/ bar.access.log common
  </VirtualHost>



The "default" host will answer ALL requests to your IP not matching any configured hostname (in your case foo.dev & bar.dev). Because of this I always put no actual site there, just a page that says "There is no website at this address" If they come directly to my IP address and not any hostname (bots usually looking for vulnerable web apps) they get "Go Away!"
gsmith
 
Posts: 218
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win XP to 2012R2/VS 6,9,11,14

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby Nobbie » 19. May 2016 19:42

stevehomer wrote:PLEASE can we have a sticky for setting up virtual hosts.


Of course:

https://httpd.apache.org/docs/current/en/vhosts/

I cannot make it a sticky, ask Bitnami (or "Altrea" here in this forum) to do so.
Nobbie
 
Posts: 9803
Joined: 09. March 2008 13:04

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby stevehomer » 21. May 2016 19:56

gsmith wrote:How about Apache's error.log and if nothing else, starting Apache from the command line?



Well added

Code: Select all
# We can use "Define" in Apache 2.4 and it's surprising it is not used more
Define DOCROOT "c:/xampp/htdocs"

# The default (and first VirtualHost) must be pointed to the same DocumentRoot as the
# (global) DocumentRoot in httpd.conf

  <VirtualHost _default_:80>
      DocumentRoot "${DOCROOT}"
  </VirtualHost>

# Now you can start adding more hosts

# foo.dev
  <VirtualHost *:80>
      DocumentRoot "${DOCROOT}/foo.dev"
      ServerName foo.dev
      ServerAdmin webmaster@foo.dev
      CustomLog /logs/ foo.access.log common
  </VirtualHost>

# bar.dev
  <VirtualHost *:80>
      DocumentRoot "${DOCROOT}/bar.dev"
      ServerName bar.dev
      ServerAdmin webmaster@bar.dev
      CustomLog /logs/ bar.access.log common
  </VirtualHost>



... and still got the same error message. The Apache error logs just report an SSL error when it DOES launch and nothing where it does not. As I said i have not managed to get anything useful out of the Windows Event Viewer (something I have never played with). At an earlier stage I did play with changing port numbers and it seemed to work BUT I may well be wrong - I did not understand how the hosts file worked (and still do not fully).

And sorry not sure how to run Apache from command line.

Any thoughts
stevehomer
 
Posts: 4
Joined: 19. May 2016 12:31
XAMPP version: 5.6.19
Operating System: Win 10

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby stevehomer » 21. May 2016 20:13

Nobbie wrote:Of course:
https://httpd.apache.org/docs/current/en/vhosts/


Yep well spent ages there. Was not a tad confusing. For example:

Each Virtual Host must correspond to a different IP address, different port number, or a different host name for the server, in the former case the server machine must be configured to accept IP packets for multiple addresses. (If the machine does not have multiple network interfaces, then this can be accomplished with the ifconfig alias command -- if your OS supports it).


BTW I don't see that we ARE using different IP addresses...

Then the examples they give are different in different places and different to the examples in the files... etc etc.

I was looking for a simple recipe to follow - that was what @gsmith gave - so we have a fixed starting point. I hope you see what I mean.
stevehomer
 
Posts: 4
Joined: 19. May 2016 12:31
XAMPP version: 5.6.19
Operating System: Win 10

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby Altrea » 21. May 2016 20:21

stevehomer wrote:BTW I don't see that we ARE using different IP addresses...

You are using name based virtual hosts, so you only need to have different host names for each virtual host.
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: 8968
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby Nobbie » 21. May 2016 21:04

stevehomer wrote:[I hope you see what I mean.


It's not that important as i know pretty well, how VirtualHosts are working.
Nobbie
 
Posts: 9803
Joined: 09. March 2008 13:04

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby stevehomer » 14. January 2017 14:14

I am bad and suffered. I never posted the solution and then on Fri 13th I reinstalled and - bang - all broken :-(

What I used was

Code: Select all
<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot C:/xampp/htdocs/temp1.dev
  ServerName temp1.dev

  <Directory "C:/xampp/htdocs/temp1.dev">
  Options Indexes FollowSymLinks Includes ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  DocumentRoot C:/xampp/htdocs/temp2.dev
  ServerName temp2.dev

  <Directory "C:/xampp/htdocs/temp2.dev">
  Options Indexes FollowSymLinks Includes ExecCGI
  AllowOverride All
  Order allow,deny
  Allow from all
  </Directory>
</VirtualHost>


This worked fine. My only problem is I cannot remember the default localhost setting that should be at the top but, apart from that, everything is fine after only about six/eight wasted hours.

The lesson: Always add that last post with the solution when you have been helped to find a solution.

NB I have to admit I have no idea how this worked but in my usual hacking way - I tried it, it worked, I stopped worrying about it and got back to work.

All the best for 2017 :-)

PS I was just trying to reinstall mySQL to just able the renaming of a file. I found a post somewhere that said as you uninstalled Xampp you would be offered the change to just reinstall mySQL. 1) that's a warning 2) is there a way of just installing one part of Xampp?
stevehomer
 
Posts: 4
Joined: 19. May 2016 12:31
XAMPP version: 5.6.19
Operating System: Win 10

Re: Sticky for virtual hosts - aka XAMPP will not start

Postby Altrea » 14. January 2017 16:38

Hi stevehomer,

just a few tips for your vhost configuration:
  • "Order allow,deny" and "Allow from all" are old Apache 2.2 syntax. Use "Require all granted" instead
  • Your very first vhost should be for localhost
  • Your vhosts DocumentRoots should not be a subdirectory of anothers host root folder (C:\xampp\htdocs\ is the root of localhost)
  • Define a Errorlog and CustumLog files for each vhost.

like so:

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

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

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



stevehomer wrote:2) is there a way of just installing one part of Xampp?

The installer does have a menu to choose which component to install, BUT i would not try to use this to reinstall or overinstall any xampp component.
If you want to get any component to it's default condition:
  • first be sure that all your current xampp components are stopped.
  • make a full backup of your current xampp folder
  • download the same xampp version you already installed but choose the zip version instead the installer one
  • extract this downloaded xampp version to a fresh folder of your choice
  • copy the component folder you want to restore (e.g. C:\temp\xampp-5.6.24\\mysql\) to your xampp folder and replace all files in there
If this will not work or you loose any data you can restore your backuped xampp folder.
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: 8968
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: No registered users and 55 guests