Page 1 of 1

VirtualHost Example / Question

PostPosted: Thu Jan 13, 2005 4:53 pm
by Michael1343
I created the following structure:

/htdocs/sites/domain1/
/htdocs/sites/domain2/

I added this to httpd.conf

<VirtualHost domain1.com:80>
ServerAdmin mike@domain1.com
DocumentRoot sites/domain1
ServerName domain1.com
ErrorLog logs/domain1.com-error_log
CustomLog logs/domain1.com-access_log common
</VirtualHost>

The Document Root is:

DocumentRoot "/Applications/MAMP/htdocs"

I cannot get domain1 to start off in the /sites/domain1/, it is just staying in "sites". Also, if I change the httpd.conf, it appears that I have to stop and restart the servers, is this correct???

PostPosted: Fri Jan 14, 2005 12:08 am
by Holger Meyer
Try this:
Code: Select all
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs"
   ServerName localhost
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs2"
   ServerName localhost2
   php_admin_value register_globals On
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs3"
   ServerName localhost3
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs4"
   ServerName localhost4
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs5"
   ServerName localhost5
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs6"
   ServerName localhost6
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs7"
   ServerName localhost7
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs8"
   ServerName localhost8
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs9"
   ServerName localhost9
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs10"
   ServerName localhost10
</VirtualHost>



You also have to edit your /etc/hosts file

Code: Select all
127.0.0.1   localhost localhost2 localhost3 localhost4 localhost5 localhost6 localhost7 localhost8 localhost9 localhost10
[/code]

PostPosted: Fri Feb 25, 2005 11:41 pm
by jeffbax
Hello, I'm trying to follow these instructions, but it seems that they just do not work for me unless I add the port in the address bar.

I am using port 8888, but if I do localhost instead of localhost:8888 it won't work... same for any other hostname. Is there anyway to get "http://localhost" or any other hostname to default to port 8888?

PostPosted: Sat Feb 26, 2005 10:06 am
by Holger Meyer
Open the preferences in the MAMP application. There you can set the apache port to 80. When restarting you are asked for your password, because applications which use ports under 1024 need administrator rights. Then all hosts should work without the :8888

PostPosted: Sat Feb 26, 2005 8:59 pm
by jeffbax
Holger Meyer wrote:Open the preferences in the MAMP application. There you can set the apache port to 80. When restarting you are asked for your password, because applications which use ports under 1024 need administrator rights. Then all hosts should work without the :8888
Yeah, I know you can change the mamp port, but I kept it so that you didn't have to put the password. Is it not possible to make a VirtualHost default to a port besides 80?

Is it a browser thing that unless the port is 80 you must add the port manually?

PostPosted: Sat Feb 26, 2005 9:35 pm
by Holger Meyer
You need to set the passwords with ports <= 1024 It doesn't matter if it is the main server or a virtual host. It is not a "browser thing" with the ports. This is standard for http. => No Port set=80

If you don't want to set the password all the time and you don't like to type the ports then you need a apache which starts at boot time like the built in apache or the apache from serverlogistics. see: http://www.mamp.de/en/help/links/

PostPosted: Sun Feb 27, 2005 4:14 am
by jeffbax
I'll stick with a password then, I really like MAMP - congrats on such a great .app :)

I guess my only other complaint besides ports, is that there is no option to start MAMP hidden. Minor though :p

PostPosted: Thu Mar 17, 2005 9:21 pm
by jackson.linux
Thanks for this. I'd also like to set domains within my local domain, so I can mirror what I do on webservers, like www.domain.tld - I usually make changes to /etc/hosts and /etc/resolv.conf but I cannot seem to make this happen here. What I'd like to do is, without changing my Mac's name servers, make it so that if I type in www.domain.tld it looks it up locally and redirects to /Users/[xxxx]/public_html/

PostPosted: Mon Mar 21, 2005 11:09 am
by Holger Meyer
insert the following line to your hostsfile:

127.0.0.1 www.domain.tld

You can find the hosts file in /etc/hosts

Just open the terminal and type:

sudo pico /etc/hosts

then edit your hosts file

To save your changes you have to type:

Control-O (^O)
RETURN
Control-X (^X)

PostPosted: Mon Mar 21, 2005 8:05 pm
by jackson.linux
Thanks Holger. I actually had done that but had a difficulty here: when I want to map domains to different user directories, or subdirectories - like:

127.0.0.1/~user1/folder2/ www.domain2.tld
127.0.0.1/~user2/folder1/ www.domain3.tld

like that? Any ideas?

Thanks much in advance,
Jack

PostPosted: Mon Jul 18, 2005 10:51 am
by antoine
Hi from Paris!

Mamp seems to be a great application : thanxs Holger !!!

I'm triying to deal with virtualhosting.
After reading all the topics from this forum relative to the subject, I started my experimentations :

First, I started by create two folders in the htdocs folder, named "sitea" end "siteb".
In this each of these folders, I placed a file named "index.php" contening this little piece off code :

Code: Select all
<?
echo("hello world !");
?>


After that, I open the httpd.conf file which path is : /Applications/MAMP/conf/httpd.conf
Then I putted those line in it :
Code: Select all
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs"
   ServerName localhost
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs/sitea"
   ServerName localhosta
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs/siteb"
   ServerName localhostb
</VirtualHost>


Then I open the terminal, open pico and started to edit the following file : /etc/hosts
I putted those lines :
Code: Select all
##
# 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 localhosta localhostb
255.255.255.255   broadcasthost
::1                       localhost


Then I open Mamp.
I typed this url : http://localhosta/ (my default port is 80)
Then : Miracle, "hello world" appears on my screen !!
I repeated the experience with htttp://localhostb/, then: "hello world" again !!!

I'm very happy I've managed to make two virtualhosts !!

My next step is to manage to have this two folders on another volume.
So I copy and paste my two folders in a new location :
/Volumes/Données/sitea and
/Volumes/Données/siteb

I open again my httpd.conf file and put those line in it :
Code: Select all
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#

NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#

<VirtualHost *>
   DocumentRoot "/Applications/MAMP/htdocs"
   ServerName localhost
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Volumes/Données/sitea"
   ServerName localhosta
</VirtualHost>

<VirtualHost *>
   DocumentRoot "/Volumes/Données/siteb"
   ServerName localhostb
</VirtualHost>


I reboot my servers and then try again : http://localhosta/
Then, no "hello world" but error 403 :

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.50 (Unix) PHP/4.3.11-dev Server at localhosta Port 80


Where is the problem and where is the solution ?

Antoine

PS : I'm a newbie in the mac world, so sorry if the answer seems to be little bit evident for you ;)
PPS : Sorry for my bad english, hope it will be understood.

PostPosted: Mon Jul 18, 2005 1:32 pm
by antoine
Hi,

This error 403 was just because of the accentued character in my path :
.../Données/...

Without this accentued character, everything working perfect !

Bye

Antoine.

PostPosted: Sat Jul 29, 2006 9:31 pm
by bugsmi0
interesting, I set everything up according to the way you did it and exactly how you set yours up and it didn't work when I go to localhosta I get nothing

PostPosted: Mon Aug 28, 2006 8:09 pm
by bugsmi0
Holger Meyer wrote:Open the preferences in the MAMP application. There you can set the apache port to 80. When restarting you are asked for your password, because applications which use ports under 1024 need administrator rights. Then all hosts should work without the :8888


I have found this to not be true, even when changing to port :80 you still can't type in a regular url http://www.test.site/ without having to put in :8888 or :80 whever the default port is

has someone ever gotten this to actually worh ?