VirtualHost Example / Question

You can ask general questions about MAMP here.

Moderator: severin

VirtualHost Example / Question

Postby Michael1343 » Thu Jan 13, 2005 4:53 pm

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???
Michael1343
 
Posts: 1
Joined: Thu Jan 13, 2005 4:48 pm

Postby Holger Meyer » Fri Jan 14, 2005 12:08 am

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]
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby jeffbax » Fri Feb 25, 2005 11:41 pm

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?
jeffbax
 
Posts: 7
Joined: Fri Feb 25, 2005 11:39 pm

Postby Holger Meyer » Sat Feb 26, 2005 10:06 am

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
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby jeffbax » Sat Feb 26, 2005 8:59 pm

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?
jeffbax
 
Posts: 7
Joined: Fri Feb 25, 2005 11:39 pm

Postby Holger Meyer » Sat Feb 26, 2005 9:35 pm

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/
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby jeffbax » Sun Feb 27, 2005 4:14 am

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
jeffbax
 
Posts: 7
Joined: Fri Feb 25, 2005 11:39 pm

Postby jackson.linux » Thu Mar 17, 2005 9:21 pm

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/
jackson.linux
 
Posts: 2
Joined: Thu Mar 17, 2005 9:18 pm

Postby Holger Meyer » Mon Mar 21, 2005 11:09 am

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)
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby jackson.linux » Mon Mar 21, 2005 8:05 pm

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
jackson.linux
 
Posts: 2
Joined: Thu Mar 17, 2005 9:18 pm

Postby antoine » Mon Jul 18, 2005 10:51 am

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.
antoine
 
Posts: 2
Joined: Wed Jul 13, 2005 1:54 pm
Location: Paris, France

Postby antoine » Mon Jul 18, 2005 1:32 pm

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.
antoine
 
Posts: 2
Joined: Wed Jul 13, 2005 1:54 pm
Location: Paris, France

Postby bugsmi0 » Sat Jul 29, 2006 9:31 pm

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
bugsmi0
 
Posts: 35
Joined: Wed Mar 08, 2006 2:47 pm

Postby bugsmi0 » Mon Aug 28, 2006 8:09 pm

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 ?
bugsmi0
 
Posts: 35
Joined: Wed Mar 08, 2006 2:47 pm


Return to General questions

Who is online

Users browsing this forum: No registered users and 7 guests