Serving several host/domain names on local machine - windows-7

I have a local PHP server on a Windows machine and the trouble I am having is that within the main root 127.0.0.1/localhost I would like to have several folders/sites that I can call on.
At present I can do localhost/siteA or localhost/siteB with no problem, but what I would like to do is to assign these locations test domain names:
EG: localhost/siteA would be sitea.dev, localhost/siteB would be siteb.dev
Not a problem as I have set up one on the host file and vhost config files.
mysites.dev which is linked to the root/localhost. So I can use it as above
mysites.dev/siteA and mysites.dev/siteB
But I would like to give each of these sites its own vhost name as mentioned above. So I have added the following:
Hosts File
127.0.0.1 mysites.dev
127.0.0.1 sitea.dev
vhost file
<VirtualHost *:80>
DocumentRoot "C:\Websites\"
ServerName mysites.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Websites\sitea\"
ServerName sitea.dev
</VirtualHost>
The trouble is that whichever one I call they all seem to simply load the first one, or at least it seems like that, but without the vhost details they all still go to the root so it looks like the host file is directing them to 127.0.0.1 and that it the vhost file seems to be ignored.
SO what am I missing in order to hook up mty individual local sites?
SOLVED: See my answer will mark it as the correct one when i can in a few days.

Your vhosts are both trying to catch anything that comes in on port 80: <VirtualHost *:80>.
You need to specify the vhost name to point to a particular folder:
<VirtualHost sitea.dev:80>
DocumentRoot "C:\Websites\sitea\"
ServerName sitea.dev
</VirtualHost>
<VirtualHost siteb.dev:80>
DocumentRoot "C:\Websites\siteb\"
ServerName sitea.dev
</VirtualHost>
You can find more info on this in the Apache docs: http://httpd.apache.org/docs/2.2/vhosts/examples.html

Well i do feel stupid. After a long look i then noticed that in the config file it was not calling in the vhost file as i placed them in the main httpd.conf and it worked.
So i had to uncomment the following within the httpd.conf file:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Related

Public folder must be the root if virtual server on Apache is setup correctly

My project name is lsapp (which is inside htdocs)
The problem is when I go to localhost or localhost/lsapp the directory of files is shown on the browser.
I have setup up the C:\xampp\apache\conf\extra
and modified httpd-vhosts.conf as required, Opened hosts files in C:\Windows\System32\drivers\etc and modified as required.
I have checked several times for any typos etc. Everything in these files are now fine.
And there is another file httpd.conf in which I have removed the # in the second line as follows.
.# Virtual hosts
Include conf/extra/httpd-vhosts.conf
One thing is I have found two http.conf files, in the following different locations. All these files are similar. Do I have to do
1) C:\xampp\apache\conf
(The setting is as below)
.# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2) C:\xampp\apache\conf\original
.# Virtual hosts
.#Include conf/extra/httpd-vhosts.conf
Also there is one more http-vhosts.conf file inside C:\xampp\apache\conf\original\extra
IT HAS NO # AND IS AS FOLLOWS:
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "${SRVROOT}/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
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "${SRVROOT}/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
At this point Im not sure about the changes have to me made to these files.
I have restarted Apache and nothing changed.
No codes in this question
The public folder must be the root and the Directory must not be visible on the browser.
On browser lsapp.test gives OBJECT NOT FOUND! ERROR 404 Also it automatically turns to http://lsapp.test/home
This is how the above mentioned files should be setup:
(C:\xampp\apache\conf\extra) httpd-vhosts.conf
....
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public/"
ServerName lsapp.dv
</VirtualHost>
(C:\Windows\System32\drivers\etc) hosts
127.0.0.1 localhost
127.0.0.1 test.com
127.0.0.1 lsapp.dv
(C:\xampp\apache\conf) httpd.conf
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
When you open the upper file, remove the # character from the beginning of the line so that it should look like the above one.
Then restart your local server and go to browser and type in lsapp.dv.

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.

OSX Apache Virtualhost returns only default page

I have a problem using the build-in apache webserver under ElCapitan.
I want to set up my Sites-Directory in my users-directory. This works fine by adding a user config and and so on. So my localhost/~Fabian gives me the content of /User/Fabian/Sites/index.php.
Now I am trying to set up virtual hosts in this directory, e.g. /User/Fabian/Sites/Projekte/testsite.me/public.
So I activated the virtualhost module and included it in my httpd.conf. After this, I set up a virtualhost in the httpd-vhost.conf:
</VirtualHost *:80>
ServerAdmin xyz#blubber.de
DocumentRoot "/Users/Fabian/Sites/Projekte/testsite.me/public"
ServerName testsite.me
ErrorLog "/Users/Fabian/Sites/Logs/testsite-error_log"
CustomLog "/Users/Fabian/Sites/Logs/testsite-custom_log" common
</VirtualHost>
I also added the ServerAlias to my hosts file
127.0.0.1 testsite.me
Trying to open http://testsite.me shows me the default "It works"-page.
Running apachectl configtest gives me an syntax error:
httpd: Syntax error on line 499 of /private/etc/apache2/httpd.conf: Syntax error on line 74 of /private/etc/apache2/extra/httpd-vhosts.conf: </VirtualHost without matching <VirtualHost section
Line 499 in httpd.conf looks like this:
Include /private/etc/apache2/extra/httpd-vhosts.conf
Line 74ff of httpd-vhosts.conf contain the virtualhost I defined above.
Any idea how to solve this problem? What is a VirtualHost section?
Thank you!
You start your vhost definition with </VirtualHost *:80>
That should be <VirtualHost *:80> without the slash.
Although the apache config files are not xml, the Syntax for starting and ending sections are the same; so you start with <tag> and end with </tag>.

Virtual Hosts not working XAMPP 1.8.3

Im trying to set up a virtual host using my local xampp stack but after following many tutorials i simply can't work out where im going wrong.
Here is what i added to my httpd-vhost.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot E:\Programs\xampp\htdocs
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:\Programs\xampp\htdocs\CVCMS
ServerName cvcms.dev
<Directory "E:\Programs\xampp\htdocs\CVCMS">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here is my hosts file
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lmlicenses.wip4.adobe.com
127.0.0.1 lm.licenses.adobe.com
127.0.0.1 cvcms.dev
I have restarted apache after every change, i have made sure http.conf is linked to the httpd-vhosts file.
The issue is when i type in the domain cvcms.dev it shows the xampp splash page instead of the index.php in my cvcms folder.
Any ideas why?
Thanks
please remember to add the quotes to your virtual host document root path. At the same time what you need to to do enable them is to find httpd.conf , in this version it should be in your etc folder within your XAMPP's root folder.
Look out for :
# Virtual hosts
#Include etc/extra/httpd-vhosts.conf
Since '#' is a comment prefix, you have to uncomment "#Include etc/extra/httpd-vhosts.conf"
See if this works. Remember to restart your XAMPP's apache server to read the new settings you've just set. Cheers !
You can read more on this here.

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