Setting up virtual hosts on El Capitan - macos

What I've done is:
Added this to httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/site1"
ServerName site1.loc
ServerAlias www.site1.loc
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/site2"
ServerName site2.loc
ServerAlias www.site2.loc
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
And in hosts file, I added this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
And finally in httpd.conf I uncommented this line:
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
I have restarted apache after this and after I have tried to run something like this:
http://site1/index.html
or http://site2 I get an error which saying:
This site can’t be reached
I am missing something very obvious? It was a long time I did this on Windows, so I guess I made some silly mistake. Also I get :
You don't have permission to access / on this server.
when I try to reach localhost.

Actually it worked after I have changed these:
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
to this:
127.0.0.1 site1.loc
127.0.0.1 site2.loc

Related

Virtualhost always redirect to localhost root directory on Mac

When I am trying to access watheeq.local it returns me to localhost root directory "/Users/abdelrahmanmuntaser/Sites" here exactly, i want to access my website which is located at "/Users/abdelrahmanmuntaser/Sites/watheeq/web", sorry I am newbie at macOS, do I missing something ?
This is my httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/usr/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName watheeq.local
ServerAlias watheeq.local
DocumentRoot "/Users/abdelrahmanmuntaser/Sites/watheeq/web">
<Directory "/Users/abdelrahmanmuntaser/Sites/watheeq/web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog "/private/var/log/apache2/watheeq.local-error_log"
CustomLog "/private/var/log/apache2/watheeq.local-access_log" com$
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/abdelrahmanmuntaser/Sites/
</VirtualHost>
This is my hosts file
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 watheeq.local
127.0.0.1 wath.local
::1 wath.local
enter code here

Creating subdomains in Xampp server windows

I am trying to create sub-domains on my localhost to be accessed concurrently by my team but only the first project is loaded even when the url for the second domain is typed in the browser.
So far I have tried changing the httpd-vhosts.conf file
<VirtualHost *:80>
ServerAdmin webmaster#smartsacco.localhost.com
DocumentRoot "C:/xampp/htdocs/smartsacco/public"
ServerName smartsacco.localhost.com
ErrorLog "logs/smartsacco.localhost.com-error.log"
CustomLog "logs/smartsacco.localhost.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#mfarmer.localhost.com
DocumentRoot "C:/xampp/htdocs/Mfarmer/public"
ServerName mfarmer.localhost.com
ErrorLog "logs/mfarmer.localhost.com-error.log"
CustomLog "logs/mfarmer.localhost.com-access.log" common
</VirtualHost>
And also modified the hosts file
127.0.0.1 localhost
::1 localhost
127.0.0.1 smartsacco.localhost.com
127.0.0.1 mfarmer.localhost.com
Saddly only the contents of smartsacco.localhost.com is loaded even when I type mfarmer.localhost.com. What could Be wrong or and what can I do to have them both working?
Since your code is correct, I suggest you restart Apache server and maybe the entire computer

How to setup virtual host in zend apache2.4 and window 7?

I am setting virtual host in my local but not success. pls help me check.
Server local info.
Zend apache2.4
system: window 7.
my config:
the content of file httpd.conf:
....
include extra/httpd-vhost.conf
....
file httpd-vhost.conf:
<VirtualHost *:80>
ServerAdmin girl.test
DocumentRoot "C:\localhost\source"
ServerName girl.test
ServerAlias www.girl.test
ErrorLog "logs\girl-error.log"
CustomLog "logs\girl-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin boy.test
DocumentRoot "C:\localhost\source"
ServerName boy.test
ErrorLog "logs\boy-error.log"
CustomLog "logs\boy-access.log" common
</VirtualHost>
File: etc/hosts I add two line
127.0.0.1/source girl.test
127.0.0.1/source boy.test
After I restart service and go to:
girl.test get message
This site can’t be reached girl.test’s server IP address could not be
found.
127.0.0.1/source is work.
pls help me check, Many thanks.
I have fixed this issue when change file etc/hosts to 127.0.0.1 girl.test 127.0.0.1 boy.test

Virtual host on Windows 10 with Apache 2.4

Can you tell me please what am I doing wrong in Virtual host settings?
I am editing two files:
Apache/conf/extra/httpd-vhosts.conf and Windows/System32/drivers/etc/hosts
httpd-vhosts.conf looks like
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias www.scouttautomotive.com
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName bosp.sk
ServerAlias bosp.sk.localhost
DocumentRoot "C:/Apache24/htdocs/bosp/web"
</VirtualHost>
hosts file looks like
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 scouttautomotive.com
127.0.0.1 bosp.sk
What is wrong with it? I am realy confused cause bosp.sk virtual host works well.
After setting the domain ip to 127.0.0.1 to host file, You must restart your computer or flush dns cache to get that applied. Did you do?
So look at these config files and note that difference is only in the last letter of ServerName.
httpd-vhosts.conf
<VirtualHost 127.0.0.1>
ServerName scouttautomotive.com
ServerAlias scout.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName scouttautomotiv.com
ServerAlias drom.com.localhost
DocumentRoot "C:/Apache24/htdocs/scouttautomotive/web"
</VirtualHost>
hosts
127.0.0.1 scouttautomotive.com
127.0.0.1 scouttautomotiv.com
First version redirects me to one hosting which offers this domain to sell. Second version works well as virtual host. Both are created in the same time. So it looks command ipconfig /flushdns may not be enough.
Another possible solutions can be find here https://serverfault.com/questions/452268/hosts-file-ignored-how-to-troubleshoot Good luck!

need help with xampp virtual host

I am using XAMPP, Apache 2.2.17. I have added virtual host but my virtual host and localhost both point to the same location. Here is my code in httpd-vhosts.conf
<VirtualHost www.domain.tld:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot "C:/xampp/htdocs/workspace/testsite"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/xampp"
ServerAlias localhost
ServerName localhost
</VirtualHost>
With the above code, I get testsite with www.domain.tld so that is good. But If i type localhost, it will go to testsite as well. If I move ahead of test site then localhost goes to localhost good and www.domain.tld goes to localhost too. I tried different setting for localhost as like
<VirtualHost *>
<VirtualHost localhost:80>
and removing *.domain.tld from domain.tld but nothing works. Am I missing something obvious?
My own answer: The following code fixed the problem
<VirtualHost *:80> <--- * fixed the problem, apache 2.2 doc does say it must match www.domain.tld, which caused problem for other Virtual hosts
ServerName www.domain.tld
ServerAlias domain.tld
DocumentRoot "C:/xampp/htdocs/workspace/patriot2"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/xampp"
ServerAlias localhost
ServerName localhost
</VirtualHost>
please change your ServerName from virtualhost to a local IP address such as 127.0.0.2.
ServerName domain.tld is an example of using "domain.com" where .tld is replaced by .com for your domain.

Resources