<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
Related
I just realized that nothing else on WAMP is accessible unless it's under the virtual host alias. For example: if I name my vHost 'mysite.dev', I can only access mysite.dev and everything else gives a 403 forbidden error. If I add a vHost called anothersite.dev in addition to mysite.dev, only those sites can be accessed. The only thing under localhost that I can access is PHPMyAdmin. I have uncommented the line that includes vHosts.conf in the Apache httpd.conf file. This problem does not happen until I modify the vHosts.conf file. Here is the config for the other files:
vHosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "c:/Apache24/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Windows hosts file:
127.0.0.1 localhost
127.0.0.1 mysite.dev
Ok first, the first 2 VHOST definitions in the httpd-vhost.conf file (vhost and vhost2) are examples, supplied by Apache, to help you get started and of course point to folders that do not exist so and should be removed.
Second When you create a Virtual Host you should include the access privilages for the VHOST in a <Directory....> group.
Third, you should always create a VHOST for localhost as once VHOSTs are created Apache ignores the localhost definition in httpd.conf
So your httpd-vhost.conf file should look like this
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "W:/wamp/www"
ServerName localhost
<Directory "W:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "W:/wamp/www/mysite"
ServerName mysite.dev
ErrorLog "logs/mysite.dev-error.log"
CustomLog "logs/mysite.dev-access.log" common
<Directory "W:/wamp/www/mysite">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Once you have done this, you now need to edit your c:\windows\system32\drivers\etc\hosts file to look like this. You need to have admin privilages to edit this file, also some anti virus suites also protect this file, so you may need to stop that protection temporarily in order to amend this file.
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev
Then restart the dnscache to pick up these changes, from a command line also started with admin privilages.
net stop dnscache
net start dnscache
This post may help you understand more about Virtual Hosts
I am trying to setup the virtual host for apache on Mac.
Here is my virtual host setting in /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin localhost
DocumentRoot "/Users/Ivy/Sites/Symfony"
ServerName symfony.dev
ErrorLog "/private/var/log/apache2/symfony.dev-error_log"
CustomLog "/private/var/log/apache2/symfony.dev-access_log" common
<Directory "/Users/Ivy/Sites/Symfony">
options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Additionally, editing the file in /etc/hosts
127.0.0.1 symfony.dev
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
192.168.43.168 matrixdemo.squiz.net
But when i go to symfony.dev in the web browser, it cannot connect to. could someone help me on that?
Note: tried to restart the apache several times
Try this it will work
NameVirtualHost *:80
#Do not forget to include server name and server alias in host file
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "D:\Local server\htdocs\localhost"
CustomLog logs/localhost.access.log combined
ErrorLog logs/localhost.error.log
</VirtualHost>
You could make it
<VirtualHost symfony.dev>
ServerName symfony.dev
ServerAdmin your.mail#whatever.com
DocumentRoot "/Users/Ivy/Sites/Symfony/web"
ErrorLog "/private/var/log/apache2/symfony.dev-error_log"
CustomLog "/private/var/log/apache2/symfony.dev-access_log" combined
<Directory "/Users/Ivy/Sites/Symfony/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
=> "Directory" instructions should be for your root-symfony-directory/web folder, as your document root.
=> What's this "common" behind your Custom Log directory ? Did you mean "combined" ?
=> In symfony2, you need to make sure that all the requests are directed to you bootstrap - this is where rewrite engine comes in. Oh, But I see this bit has moved into the .htaccess in earlier versions of symfony :o So no need for it here. Note that you have configuration instructions for apache and symfony2 here
There is much more science behind this, but these are the parameters I use for my setup. For more info, read the docs !
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
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.
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