OSX Apache Virtualhost returns only default page - macos

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>.

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>

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.

Serving several host/domain names on local machine

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

Laravel setup failed to open stream

I'm trying to setup laravel but its proving to be a right mere! I've cloned it from github and also used composer to clone laravel and I've got both of these techniques working which is good because its something I really wanted to learn. Simpler than I thought.
However when I try to navigate to my laravel directory which is called iProject so I type into my browser localhost/iProject I get a list of directories which is not what I expected, I expected to be directed to at least the hello.php page.
I've tired another technique as described in a Net-tuts tutorial which is setting up a listening port and there I am then going through localhost:8888, but when using this technique the following error message appears:
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'public/' include_path='.;C:\xampp\php\PEAR') in Unknown on line 0
Setting up Virtual Host (as per responses received)
When I setup the virtual host I am redirected to xampp the url goes to iproject.dev/xampp
I've setup a virtual host as so:
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 iproject.dev
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/iProject/public"
ServerName iproject.dev
ServerAlias iproject.dev
ErrorLog "logs/iProject.liog"
CustomLog "logs/custom.iProject.log" combined
<Directory "C:/xampp/htdocs/iProject/public">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
You can simply use (I've same setup for all of my projects) in httpd-vhosts.conf file
<VirtualHost iproject.dev>
DocumentRoot "C:/xampp/htdocs/iProject/public"
ServerName iproject.dev
</VirtualHost>
Also, add the following line in you C:\Windows\System32\drivers\etc\hosts file
127.0.0.2 iproject.dev # 127.0.0.2 could be 127.0.0.3 or ...4/...5
For example, this is a part of my hosts file in win-7
127.0.0.1 localhost
127.0.0.1 127.0.0.1
127.0.0.2 alimsearch.dev # alimsearch.co.uk
127.0.0.3 laravel4.dev
# ...
And part of my httpd-vhosts.conf file
<VirtualHost alimsearch.dev>
DocumentRoot "D:/xampp/htdocs/alimsearch/public"
ServerName alimsearch.dev
</VirtualHost>
<VirtualHost laravel4.dev>
DocumentRoot "D:/xampp/htdocs/laravel4/public"
ServerName laravel4.dev
</VirtualHost>

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