configuring virtual host and localhost redirecting to the xampp folder - apache

I have problem with creating virtual host. I am using Windows 7 x64 Professional. In file C:\Windows\System32\drivers\etc\hosts I have only this lines:
127.0.0.1 myhost
127.0.0.1 www.myhost
And in file C:\xampp\apache\conf\extra\httpd-vhosts.conf I have this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Users/Me/Dropbox/Project/public"
ServerName myhost
ServerAlias www.myhost
<Directory "C:/Users/Me/Dropbox/Project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And of course I have restared my Apache server after adding this lines in those files.
Unfortunatly typing myhost or www.myhost in my browser redirect me to the myhost/xampp.
I have already search and I have found on google and also on stackoverflow description how to configure virtual hosts using xampp but how can I recognize I have done everything alright. I know that my problem isn't new but I didn't found working solution for me.
I have also recognized that typing localhost in my browser redirect me alsto localhost/xampp. I don't know whether these problems are linked in my case.

I had this same issue. Your first request is redirecting to the htdocs root directory. If you look at index.php in the htdocs directory, you can see very brief code that takes the incoming request and redirects it to the xampp directory.
I fixed it by fiddling with the httpd-vhosts.conf file. In your case, try making the following edits:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\xampp\htdocs\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "C:\Users\Me\Dropbox\Project\public"
ServerName www.myhost
ServerAlias www.myhost
<Directory "C:\Users\Me\Dropbox\Project\public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

I had a similar issue and found that I had to go to my Apache24 main httpd.conf file and uncomment around line 501 "Include conf/extra/httpd-vhost.conf"
I had never used that before and it was still #'ed out. Hope this helped anyone not finding other answers here. My Apache24 can now see my vhost file.

You need to enable name-based virtual hosting.
Near the top of the file in C:\xampp\apache\conf\extra\httpd-vhosts
uncomment #NameVirtualHost *:80
i.e. from:
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
To:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
(Note the last line now is uncommented).
Worked like a charm for me. :)

try this
[ file : C:\xampp\apache\conf\extra\httpd-vhosts.conf ]
<VirtualHost basic.test:80>
DocumentRoot "C:/xampp/htdocs/basic/public/"
ServerName basic.test
</VirtualHost>
[ file : C:\Windows\System32\drivers\etc\hosts ]
(open as admin)
127.0.0.1 basic.test
127.0.0.1 localhost

For me replacing this one <VirtualHost *:80> to this <VirtualHost 127.0.0.1:80> working fine.

Related

MAMP Apache Won't Start with Virtual Host for SimpleSAMLphp

I'm attempting to configure simpleSAMLphp within a MAMP/Apache environment on Windows 10 and below is my httpd-vhosts.conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/simplesamlphp/www>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here is my /etc/hosts file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# Virtual Hosts
127.0.0.1 simplesamlphp
Apache starts via MAMP totally fine without including this httpd-vhosts.conf file in my httpd.conf file, but as soon as its included, Apache will not start so the issue appears to be with httpd-vhosts.conf. No errors are shown in the apache_error.log file. My Apache version is 2.2 so I believe my Directory directives in my second VirtualHost are correct.
I've tried double quoting the DocumentRoot's, directory paths etc, and also tried backslashes over forward slashes. I spent most of yesterday trying to figure this out while scouring the web but nothing I found has made this work.
Any help is much appreciated!
Try this modified config
The path in Directory header same as DocumentRoot!
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/htdocs/pro-dashboard>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
So oddly enough, taking out what I had in httpd-vhosts.conf and simply putting it in my httpd.conf file makes Apache start back up.

Xampp Virtual Hosts redirecting to localhost instead of the right folder

I try to use a Virtual Hosts on xampp (apache 2.4), on Windows 10.
I've been through a lot of topics and posts and tried every combination of port etc, and I couldn't make it work.
When I try to access my project it redirects me to localhost (default).
Here's my system32/drivers/etc/hosts :
127.0.0.1 localhost
127.0.0.1 yanns-properties.test
Here's my httpd-vhosts.conf :
NameVirtualHost *:8080
<VirtualHost _default_:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
# Site: yanns-properties
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/yanns-properties"
ServerName yanns-properties.test
CustomLog "C:/xampp/htdocs/yanns-properties/custom.log" combined
<Directory "C:/xampp/htdocs/yanns-properties">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I also put in my httpd.conf file :
Listen 80
Listen 8080
When I try to access yanns-properties.test, it redirects me to localhost (with list of file since I renamed index).
I tested with various port, with my project in a different folder ... I don't know what to do anymore.
Thanks for your help !
I

Add Virtual Host for Localhost Ampps

<VirtualHost *:80>
DocumentRoot "C:/Program Files (x86)/Ampps/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Program Files (x86)/Ampps/www/proj"
ServerName proj.local
</VirtualHost>
How do I bind a specific "domain" (virtual host domain) to one location? Above points proj.local to localhost as well.
As you said you are using AMPPS, I suppose you are adding this instructions to the folder:
AMPPS/apache/conf/extra/httpd-vhosts.conf
With that in mind I'll show an example of configuration.
<VirtualHost project.local:80>
<Directory "/Users/you/yourproject">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName project.local
ServerAlias project.local 127.0.0.1
ScriptAlias /cgi-bin/ "/Users/you/yourproject/cgi-bin/"
DocumentRoot "/Users/you/yourproject"
ErrorLog "/Applications/AMPPS/apache/logs/project.error_log"
CustomLog "/Applications/AMPPS/apache/logs/project.access.log" combined
</VirtualHost>
All right. After doing that, you will have to add to your hosts file. In Mac they are located in:
/etc/hosts
If you are using a Windows environment you will find the hosts file in:
c:\windows\system32\drivers\etc\hosts
Attention: You may have to type your password again or allow the program you're using to edit the file to use administrator privileges.
Then you'll add your local IP and the hostname to it. Just like this:
127.0.0.1 project.local
If you don't add the URL to the hosts file that won't work.
Have you tried with <VirtualHOst proj.local:80>? You should be able to find more examples here: http://httpd.apache.org/docs/2.2/vhosts/examples.html
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName xampp.local
ServerAlias www.xampp.local
</VirtualHost>
after adding it at the end of your httpd-vhosts.conf file restart your xampp and also add following lines to your hosts file available at C:\Windows\System32\Drivers\etc\hosts
127.0.0.1 xampp.local

Both virtual hosts go to default

I'm trying to add a virtual host to xampp server but it seems I'm missing something because the second site does not show up, localhost is displayed instead. I don't know what is wrong with these settings:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/site1/public"
ServerName site1
<Directory "C:/xampp/htdocs/site1/public">
AllowOverride All
Order allow,deny
Allow from all
Options all
</Directory>
</VirtualHost>
I added the virtual host to the hosts file:
127.0.0.1 localhost site1
Maybe try just adding
127.0.0.1 site1.local
to your hosts file (on windows C:\windows\system32\drivers\etc\hosts)
save file and make sure to restart xampp from the control panel
Give this a try:
In your httpd-vhosts.conf file:
<VirtualHost localhost>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost site1>
DocumentRoot "c:\xampp\htdocs\site1\public"
ServerName site1
<Directory "C:\xampp\htdocs\site1\public">
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
And in your hosts file:
127.0.0.1 localhost
127.0.0.1 site1
What I've done here:
Instead of using *:80, I'm using the name of the host. This gives it a more direct matching approach.
I've exchanged all forward slashed with backslashes. This doesn't really make a difference, but Windows uses backslashes - this is just a rule of thumb.
I have removed NameVirtualHost as, to my current knowledge, it does not make any difference, and thus depreciated. Future versions may recogise it as an unknown key.
Yeah, just use the solution from Mike and do not forget to uncomment line
#Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
within your httpd.conf file

Having trouble with multiple hosts on Apache Snow Leopard

I am running Apache on my Mac OS X (Snow Leopard) machine. I want to be able to set up multiple hostnames so that I can develop and test multiple sites at the same time, but I can't seem to get this to work.
Here's what I've tried:
In my etc/hosts file I've set added these entries:
127.0.0.1 testsite1.localdev.com
127.0.0.1 testsite2.localdev.com
Then, in apache2/httpd.conf I have added these entries:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite1
ServerName testsite1.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite1">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents/www/development/testsite2
ServerName testsite2.localdev.com
<Directory "/Library/WebServer/Documents/www/development/testsite2">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
But happens is that both hostnames resolve to the first one listed in the httpd.conf file -- in this case, testsite1. If I switch their positions, then they both resolve to testsite2.
I've also tried changing the area that reads *:80 and replacing that with the specific hostnames for each site, but that has no effect.
I am being sure to reboot apache after each change.
Thanks for any help!
Gary
in /etc/apache2/httpd.conf uncomment the vhost file like:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
in /private/etc/apache2/extra/httpd-vhosts.conf use...
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
ServerName localhost
</VirtualHost>
# local test site
<VirtualHost *:80>
<Directory /Users/<youruser>/Sites/test>
AllowOverride All
</Directory>
DocumentRoot "/Users/<youruser>/Sites/test"
ServerName test.local
</VirtualHost>
Be sure that your and Sites folders have permissions of 755
and be sure that you add to your /etc/hosts file...
# test
127.0.0.1 test.local