Help setting up virtual hosts.

You can ask general questions about MAMP here.

Moderator: severin

Help setting up virtual hosts.

Postby mikulla » Tue Aug 02, 2005 1:31 am

Hello.

I would like to set up name based virtual hosts. I found another post on the subject, but it was a tad confusing.

Right now I view my site at http://localhost:8888/mattmikulla_txp/ .

Can someone give me a simple, concise, step by step on how to set up name base virtual host? Also, do I have to go into netinfo manager to duplicate and rename the localhost?
Fine Art | Photography | Design | Illustration
http://www.artrogue.com/
mikulla
 
Posts: 15
Joined: Sun May 01, 2005 2:27 pm

Postby Holger Meyer » Tue Aug 02, 2005 8:16 am

You don't need to edit the netInfo. Just make an entry in the /etc/hosts file.

eg:

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 localhost2 localhost3
255.255.255.255   broadcasthost
::1             localhost



You can edit the file with pico:

1. Open the terminal
2. Type: sudo pico /etc/hosts
3. Type your password
4. Edit the hosts file like above
5. press Cotrol-O and then Return to save the changes
6. press Control-X to exit pico

Then make 2 new directories in /Applications/MAMP
"htdocs2" and "htdocs3"


Now you have to edit the httpd.conf File

It is located at /MAMP/Applications/conf/apache/httpd.conf (> MAMP 1.0 final) or /MAMP/Applications/conf/httpd.conf (< MAMP 1.0 final)

You can do this with any text editor you like.

Then change the end of the httpd.conf file like this:

Code: Select all
#
# 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
</VirtualHost>

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


- restart MAMP

- Voila, thats it

You can access the hosts now with:

http://localhost:8888
http://localhost2:8888
http://localhost3: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 mikulla » Tue Aug 02, 2005 2:15 pm

Well, my purpose is to set up my site so I can use root relative urls.

Index="/"

About="/about/"

Contact="/contact/"

I have seen people say the set something so that they use a fake url locally like www.test.site ?

I would like to type the url http://www.test.site and go directly to my index page.
Fine Art | Photography | Design | Illustration
http://www.artrogue.com/
mikulla
 
Posts: 15
Joined: Sun May 01, 2005 2:27 pm

Postby Holger Meyer » Tue Aug 02, 2005 2:22 pm

then change yor hostfile like this:
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 www.test.site
255.255.255.255   broadcasthost
::1             localhost
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby mikulla » Tue Aug 02, 2005 6:16 pm

Can I use an editor like textwrangler to edit the host file instead of pico?

I am able to open it up in textwrangler no problem.

Another worry of mine: I am developing a site using textpattern. My site is held within a subfolder with the htdocs folder: /Applications/MAMP/htdocs/mattmikulla_txp .

I am afraid to rock the boat with my database. I am new to all of this. So would it be safer to instead of creating an htdocs2, htdocs3, etc, to just address the folders within the original htdocs folder.

Also, was ther purpose of creating the htdocs2, htdocs3, etc so I can develope multiple sites locally while using virtual hosts?
Fine Art | Photography | Design | Illustration
http://www.artrogue.com/
mikulla
 
Posts: 15
Joined: Sun May 01, 2005 2:27 pm

Postby Holger Meyer » Tue Aug 02, 2005 7:56 pm

Yes of course, you can edit it with textwrangler

I am afraid to rock the boat with my database. I am new to all of this. So would it be safer to instead of creating an htdocs2, htdocs3, etc, to just address the folders within the original htdocs folder.

Also, was ther purpose of creating the htdocs2, htdocs3, etc so I can develope multiple sites locally while using virtual hosts?


So if you have different domain names like localhost2 and localhost3, you need to write everytime the whole URL wit http and hostname when linking to other documents eg <a href="http://localhost2:8888/document.php">link</a>

If you have everything at one domain, you can make it in subfolders and you can link in your code like this:

<a href="/folder1/document.php">link</a>

But when typing the url in the browser you need to write the whole thing:

htttp://localhost:8888/folder1/document.php

So it is your choice what you prefer.

It has nothing to do with the database. The database is allways accessable with localhost (it doesn't matter from which virtual hosts). So it is technical the same if you use just subfolders or virtual hosts.
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby mikulla » Tue Aug 02, 2005 11:31 pm

Thanks Holger. Unfortunately I am a little more confused since so much has be covered in this post. Clarify if possible.

1. The reason for creating htdocs, htdocs2, htdocs3 is to possibly have seperate directories with seperate sites being developed. Each folder could be the root level for each site and this is what virual hosts can accomplish.

htdocs could have an index.php, htdocs2 could have it's own index php, etc, while both would need just a "/" to link to them.

Say I had an images folder withing htdocs and I wanted to call an image. Example: "/images/mypicture.jpg" .

Is this correct thinking?
Fine Art | Photography | Design | Illustration
http://www.artrogue.com/
mikulla
 
Posts: 15
Joined: Sun May 01, 2005 2:27 pm

Postby Holger Meyer » Wed Aug 03, 2005 8:14 am

Yes, thats the way it is! :)
Holger Meyer
http://www.mamp.info
holger.meyer AT mamp.info
Holger Meyer
 
Posts: 366
Joined: Sun Jan 02, 2005 10:55 am

Postby godkid22 » Sat Aug 13, 2005 3:46 am

hi guys - for some reason I've gotten this to work - but I only get folder lists for sites with index.htm as the homepage.

What's up there?
godkid22
 
Posts: 4
Joined: Sat Aug 13, 2005 3:40 am

Postby godkid22 » Sat Aug 13, 2005 3:48 am

forget it - in typing I reaized that I should've edited the httpd.conf file to use inde.htm as well - thanx anyway
godkid22
 
Posts: 4
Joined: Sat Aug 13, 2005 3:40 am

Postby godkid22 » Sat Aug 13, 2005 4:43 am

hi - a little help please...


this is my code in httpd.conf

Code: Select all
#
# 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/digisolve"
    ServerName SITEITRYING.com
</VirtualHost>


and my etc/hosts files look like

Code: Select all
127.0.0.1      localhost xxxxx.com yyyyy.com SITEITRYING.com


...but when i try SITEITRYING.com in safari it doesn't load... any ideas??
godkid22
 
Posts: 4
Joined: Sat Aug 13, 2005 3:40 am

Postby godkid22 » Sat Aug 13, 2005 4:50 am

figured it out - i mispelt the address in the etc/hosts file - i MUST be tired :(
godkid22
 
Posts: 4
Joined: Sat Aug 13, 2005 3:40 am

Postby tommyg » Wed Jan 04, 2006 6:45 am

After I do all of the things mentioned on this thread in order to set up some virtual hosts, my MAMP Apache server won't boot. Anyone else have this problem??

I'll try again in the morning after some sleep - if it happens again, I'll keep you posted.
tommyg
 
Posts: 1
Joined: Wed Jan 04, 2006 6:42 am

where is /etc/hosts ?

Postby chazilla » Sun Jan 15, 2006 12:14 pm

I've seen several references to editing /etc/hosts, but I don't see an /etc/hosts on my installation.

OS X 10.4.3

what am I missing?

thanks
chazilla
 
Posts: 2
Joined: Sat Jan 14, 2006 3:12 pm

Re: where is /etc/hosts ?

Postby TJung » Sun Jan 15, 2006 2:22 pm

chazilla wrote:I've seen several references to editing /etc/hosts, but I don't see an /etc/hosts on my installation.

OS X 10.4.3

what am I missing?


This file isn't inside your MAMP-folder.
The directory "etc" is in the root dir of your hard disk. You won't see it the Finder because it's hidden.
But if you type "sudo pico /etc/hosts" in the terminal, pico will find and open that file.

HTH,
Tobias Jung
TJung
 
Posts: 21
Joined: Fri Dec 23, 2005 2:10 am

Next

Return to General questions

Who is online

Users browsing this forum: Google [Bot] and 4 guests