vhosts only shows one root for all domains - xampp

I am using MAMP. I want separate domains to use different roots on my local computer.
I want "localhost" to go to my htdocs folder.
I want "wowzers.loc" to use /Donald/Projects/wowzers as its root.
I want "secondsite.loc" to use /Donald/Projects/secondsite as its
root.
Here is my httpd-vhosts.conf file:
NameVirtualHost *:80
<VirtualHost *>
DocumentRoot "/Users/donald/Projects/wowzers"
ServerName wowzers.loc
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/donald/Projects/secondsite"
ServerName secondsite.loc
</VirtualHost>
Right now, typing "localhost", "wowzers.loc", or "secondsite.loc" will all navigate to the first entry in my vhosts file. In this example, everything navigates to "wowzers.loc".
Why do all my servernames point to the top entry?

You should try it without the quotes around DocumentRoot and also pass the same argument from NameVirtualHost to VirtualHost i.e.: <VirtualHost *:80>
Apache documentation

Related

Windows - Apache DocumentRoot in VirtualHost ignored

On my Windows 7 PC, I'm using XAMPP => Apache to run a testing webserver. But for a certain website I don't want the regular "C:\xampp\htdocs", but a custom path - which when I work on Ubuntu I usually setup in VirtualHost just as a DocumentRoot and it works.
On this PC the target path is similar to: "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
However on this PC when I do
<VirtualHost test2020.test:443>
DocumentRoot "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
ServerName test2020.test
ServerAlias www.test2020.test
</VirtualHost>
The DocumentRoot directive is completely ignored - it still seems to target files in the default C:\xampp\htdocs
I've also tried moving the files around the system and changing forward/backward slashes with no success:
DocumentRoot "C:/Users/X/Disk External/DIRWITHDIÁCRÍCÍCS/WEBS/some path/path"
DocumentRoot C:\xampp\htdocs\testdocumentroot
DocumentRoot "C:\Users\X\www"
Also I've tried swapping order of DocumentRoot and ServerName with no success.
I've checked C:\xampp\apache\conf\httpd.conf - the line Include conf/extra/httpd-vhosts.conf IS uncommented.
And the file C:\xampp\apache\conf\extra\httpd-vhosts.conf seems to affect apache start-up when set-up wrongly.
EDIT: also I did restart apache between each try :)
What am I missing?
So it's just my idiotism, I've tried to overdomain everything, but the directive attribute inside the VirtualHost tag is for network incoming limitation. For regular cases * is just fine there, also then I had a problem with Directory tag directive because aparently there's a new directive for Apache 2.4+
<VirtualHost test2020.test:443> => <VirtualHost *:443>
Working final code:
# (or *:80 for http:// , 443 is for https://)
<VirtualHost *:443>
DocumentRoot "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path"
ServerName test2020.test
ServerAlias www.test2020.test
<Directory "C:\Users\X\Disk External\DIRWITHDIÁCRÍCÍCS\WEBS\some path\path">
# NEW&SIMPLE FROM APACHE 2.4+ !
Require all granted
</Directory>
</VirtualHost>

laravel virtual host setup not showing front-end

I have a new laptop, and am now trying to run a laravel application.
First, am trying to setup a virtual host for the project so that I can access blog.local
I went my hosts file and setup the drivers like the following:
127.0.0.1 localhost
127.0.0.1 test.local
127.0.0.1 blog.local
The for the apache configuration I have the following:
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog"
ServerName blog.local
</VirtualHost>
When I try to access my url I do not see the site but the files only:
For this and future projects, how can I create a local url and see the front-end when I visit it?
You need to address your public folder,
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog\public"
ServerName blog.local
</VirtualHost>
The document root is a directory (a folder) that is stored on your host's servers and that is designated for holding web pages. When someone else looks at your website, this is the location they will be accessing.
Change the DocumentRoot to according to your PHP project is located.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/blog/public"
ServerName blog.local
</VirtualHost>
Restart the servers after making any changes! If you don’t reset the server to apply the changes, nothing will work even though you know you’ve done everything right.

localhost/ going to laravel project

I am new to Laravel and while creating a new project, I wanted it to be named in Virtual Host. By this way,
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/logo/public"
ServerName logo.local
</VirtualHost>
I named it, defined IP address for it (127.0.0.1) in HOSTS file but now, when I write localhost/ in the address bar, instead of going to Xampp("Welcome to XAMPP"), it goes to my laravel project. I know that if I will define my localhost the same way, like
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
the problem will be solved but I don't know the reason of doing this. Why do I need to name C:/xampp/htdocs/ as localhost, if it was default before my laravel project?
if i get your meanings correct, you need add a default virtual host before other virtual host, so in your case, should be like this,
add the code block to end of the httpd.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/logo/public"
ServerName logo.local
</VirtualHost>
and edit hosts file to
127.0.0.1 localhost
127.0.0.1 logo.local

Dynamic VirtualHost and DocumentRoot and ServerName

<VirtualHost *.laravel:80>
DocumentRoot "z:\wamp\www\laravel\%1\public"
ServerName %1.laravel
</VirtualHost>
This does not work. What I'm trying to do here is have the documentroot of http://*.laravel/ be z:\wamp\www\laravel\(wildcard * value here)\public
I don't know how to get the value of the wildcard. My windows hosts file is setup correctly to point to localhost
You are looking to use VitualDocumentRoot instead of DocumentRoot
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html#virtualdocumentroot
Also, ServerName is always static (all your dynamic DocumentRoots will have the same exact ServerName). It's one of the problems with dynamic VHs.

Set up Apache virtualhost on Windows

How can I set up virtualhost for multiple domain name on Windows?
I will use it for my own test projects. I have three projects that I need to set up and at the moment I'm using xampplite for the portable Apache.
www.foo-bar.com --> direct to c:\xampplite\htdocs\foo-bar\
www.abcdef.com --> directo to c:\xampplite\htdocs\abcdef\
www.qwerty.com --> direct to c:\xampplite\htdocs\qwerty\web\
I also need to access on another project, but it just like typing
http://localhost/my-project/
How can I write the vhost configuration for that?
You need to do several steps in order to make this work.
Update the hosts file. On Windows XP, you can find it under c:\WINDOWS\system32\drivers\etc\. You should already see the first line from below. It takes care of your mentioned other project. Add the additional ones to make any requests to the mentioned virtual hosts routed back to your own machine.
127.0.0.1 localhost
127.0.0.1 foo-bar.com
127.0.0.1 abcdef.com
127.0.0.1 qwerty.com
Update the vhosts file in Apache configuration. Under your XAMPP folder, add the following to apache\conf\extra\httpd-vhosts.conf and if needed change the ports (i.e., if you use 8080 instead of port 80).
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/foo-bar/
ServerName www.foo-bar.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/abcdef/
ServerName www.abcdef.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampplite/htdocs/qwerty/web/
ServerName www.qwerty.com
</VirtualHost>
Do a quick configuration check. Open {XAMPP-folder}\apache\conf\httpd.conf your file and make sure that the following part is not commented out by a preceding # character:
Include conf/extra/httpd-vhosts.conf
Restart XAMPP.
... and you should be all setup now. Your other project should be accessible at the URI you mentioned if you just put it under C:/xampplite/htdocs/my-project/.
To get C:/xampp/htdocs/my-project/ working, I had to add the following (default?) VirtualHost to apache\conf\extra\httpd-vhosts.conf (in step 2 of MicE's tutorial).
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
127.0.0.5 abcd.com
< VirtualHost 127.0.0.5 >
ServerName abcd.com
DocumentRoot "C:\xampp\htdocs\laravel\public"
<Directory "C:\xampp\htdocs\laravel\public">
DirectoryIndex index.php
AllowOverride All
Order allow, deny
Allow from all
</Directory>
< / VirtualHost >

Resources