Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Enabling Virtual Hosts on MacOS X

Rated 4.27 (Ratings: 15) (Add your rating)

Log in to add a comment
(60 comments so far)

Want more?

 
Picture of bobdavis

Bob Davis

Member info | Full bio

User since: August 02, 1999

Last login: January 10, 2000

Articles written: 15

Enabling Virtual Hosts on MacOS X

As a web developer, it's not unusual to have a multiple sites under development at the same time. Here's how to develop as many sites as you want, with "root relative" calls for graphics, scripts, CSS, links, etc. and keep all of the files for any particular site together - and they don't even have to be in the default web server document root.

The practice is called "Name-Based Virtual Hosts". As described in the Apache documentation (thoughtfully provided by Apple with every MacOS X installation):

The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname. For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as www.company1.com and www.company2.com, without requiring the user to know any extra path information.

Apache was one of the first servers to support IP-based virtual hosts right out of the box. Versions 1.1 and later of Apache support both, IP-based and name-based virtual hosts (vhosts). The latter variant of virtual hosts is sometimes also called host-based or non-IP virtual hosts.

The instructions for adding Virtual Hosts in the Apache documents tell you what you need to change in your Apache configuration - but, they don't give you the rest of the story. To create functioning Virtual Hosts for development on your Mac, you also need to tell it that http://my.test.site resolves to 127.0.0.1 (the internal IP address of your machine - every machine on the net thinks it is 127.0.0.1) or http://localhost/. You fix this up by using Apple's NetInfo Manager (Applications/Utilities/NetInfo Manager).

NB: from here on out, you'll have to have administrator privileges on your machine. You don't need to be root, but you do need to have the ability to "sudo".

First, we need to create the pointer to localhost that we're going to use to tell Apache what files to serve as the web site.

  1. Open NetInfo Manager and browse to /machines/localhost.
  2. Click on the lock, and enter your password so that you can make changes.
  3. Duplicate "localhost" (Edit::Duplicate)
  4. Select "localhost copy" and then select the name property in the lower window
  5. Change the value of "name" from localhost to whatever your development site will be. Remember, if you choose a real domain, you won't be able to do anything (like see the web site, send mail, etc.) with that domain from this machine. I use bogus TLD's - so www.test.site works fine.
  6. Click on one of the other directories in the list, and you will be asked if you want to save your changes. Save them!

You've now made an entry in your NetInfo Manager for a bogus site that points to your local machine. If you try to go to http://www.test.site now with a web browser, you'll see the same thing you'll see if you go to http://localhost/. Which brings us to step two - creating the vhost entry in the Apache Config file.

Open Terminal and enter:

[localhost:~] bob% cd /etc/httpd/
[localhost:/etc/httpd] bob% ls -la

One of the files you see in there should be httpd.conf. You'll want to make a backup of that file - just in case. So...

[localhost:/etc/httpd] bob% cp httpd.conf httpd.conf.back
[localhost:/etc/httpd] bob% ls -la

Now you see httpd.conf and httpd.conf.back in the directory.

Now comes the fun part. You need to edit your httpd.conf file. Since it is owned by root and root is the only user with read and write permissions on the file, you will need to pretend that you are root, even if it's just for a little while. The safest way to do this is to use the "sudo" command. In the next examples, I use emacs to edit the httpd.conf file, but you also have vi and pico at your disposal, and you can use TextEdit or BBEdit if you like. I only use emacs because it's what I know and I like the safety of not having an application opened as root (which is what you'd get if you used open -a and used BBEdit or TextEdit).

So, issue the following command:

[localhost:/etc/httpd] bob% sudo emacs httpd.conf

Find the line (ctrl + s to search in emacs) that reads ### Section 3: Virtual Hosts and read the description below it. It shows an example of a name based vhost. Uncomment the line that reads #NameVirtualHost * and change it to NameVirtualHost 127.0.0.1. Below the example VirtualHost, you'll want to create your own listings now.

If you tell the server that you have one vhost on 127.0.0.1, it will presume that every call to 127.0.0.1 (including localhost) is a request for that web site - so, if you want to have http://localhost work, you need to add 2 vhost entries. It looks like this:

#       Leave this one alone - it makes sure that localhost works.
<VirtualHost 127.0.0.1>
	DocumentRoot /Library/WebServer/Documents
	ServerName localhost	
</VirtualHost>

#        Add new hosts here for development

<VirtualHost 127.0.0.1>
	DocumentRoot /Library/WebServer/Documents/path/to/files
	ServerName www.test.site
</VirtualHost>

In the listing for your test site, you can make the DocumentRoot value whatever you want. It doesn't have to be in the default web docs directory. Whatever will work for you to help you keep your files in order is fine.

Save your changes (ctrl+x, ctrl+s) and quit emacs (ctrl+x, ctrl+c). Now you have to restart Apache. In MacOS X, the easiest way to do this is in the Sharing panel in System Preferences. Turn Web Sharing off, then turn it on again. It's that simple.

Now, open a web browser and go to http://www.test.site/. If you've done it all right, you'll see the site you pointed at in the httpd.conf file. All of your root relative calls will work, and all of your files are manageable again. As you pick up new sites to build, you can easily add them like this and have a complete testing and development machine.

Bob's just this guy who lives in San Antonio, TX and works as the web guy at a hotel and freelances. He writes, codes, plans, manages, cooks, learns, reads, and sometimes drives too fast.

Just right

Submitted by markgill on July 8, 2001 - 17:29.

I had been searching docs for several days to understand what to do in netinfo manager to get a virtual host. 5 min with this article was all I needed. thanks.

login or register to post comments

Great help, next step - proper DNS

Submitted by metafeather on July 9, 2001 - 03:45.

Whilst the article will work for an individual developer, on one machine, users will not be able to access the site from machines - which can pose a problem for browser testing on different platforms.

An alternate/releated method is to use IP based Virtual Hosts - but using separate port numbers for each site. The 2 methods can be combined - instead of pointing all the ServerNames to one IP, add port declarations and Listen statements into httpd.conf.

eg:
#       Leave this one alone - it makes sure that localhost works.
#       MF: add the next line so localhost only listens to port 80 (default web server port)

Listen 80
<VirtualHost 127.0.0.1>
	DocumentRoot /Library/WebServer/Documents
	ServerName localhost	
</VirtualHost>

#        Add new hosts here for development
#        MF: Add port no to end of IP and Listen command for the port (must come first)

Listen 8080
<VirtualHost 127.0.0.1:8080>
	DocumentRoot /Library/WebServer/Documents/path/to/files
	ServerName www.test.site
</VirtualHost>

Port no's in the range 8080 + are normally beyond those used by UNIX systems so you can have as many sites as you like.

This method will work with/without messing with NetInfo - http://localhost:8080 and http://www.test.site both go to the same place for the owner of the machine, other users can access using your network IP address and port no, eg: 172.19.1.250:8080

Beyond this ...

What is NetInfo doing at this point to enable this? Is it editing /etc/hosts? or using its own method? What happens if you set a hostname in /etc/hostconfig instead of it being -AUTOMATIC-?

Anyone have any instructions for setting up a 'proper' DNS service?

There used to be the option of switching DNSSERVER=-NO- to YES in /etc/hostconfig, but that no longer works automagically - although named still seems to be present.

With DNS you could match the virtual host entries with Alias' in the DNS config files and anyone can add your machine to their TCP/IP settings as a DNS server in addition to there normal ones to see your sites.

Good info always welcome

login or register to post comments

Specifics for IP based Virtual Host

Submitted by fxg97873 on July 9, 2001 - 10:50.

At my university, getting subdomains with fixed IPs for your server is pretty easy.

If you are using Mac OS X, and want to add multiple IPs, use the "ifconfig" command with the "alias" option.

ifconfig interface inet ipaddress netmask subnet alias

Ex.
ifconfig en0 inet 10.0.0.1 netmask 255.255.255.255 alias

en0 is the interface (NIC) and will be different according to your interface (use ifconfig -a) to find what interfaces you have.

If the ip address that you are attaching as an alias is in the same subnet as your default ip address, then use a netmask of 255.255.255.255.

Follow the latter article and comments for the configuration of Apache.

Fernando Gonzalez Jr.
Houston, Tx

login or register to post comments

thanks and great tips!

Submitted by bobdavis on July 9, 2001 - 16:49.

First of all, thanks for all of the good feedback. I'm happy to see that the article is of use.

Secondly, the method I describe is really intended for a developer on a single machine working more or less by him/her self. Since I went freelance, most of the work I'm doing is on my PowerBook, so I might have gotten locked into that mentality. Thanks for the great tips on doing port addressing and subdomains. That helps a lot.

Metafeather: NetInfo Manager esentially handles your hosts information and your lookupd info. You can manage users, groups, DNS, etc. all from the one applicationn. try typing man netinfo into the terminal and see what you get. Apple has some more extensive docs for administrators on their site that might help.

login or register to post comments

Tried both, having trouble...

Submitted by mjw8 on October 7, 2001 - 01:02.

My intent is to just be on a single machine developing by myself. I tried both methods. My latest configuration -- with no changes to the original /etc/hosts:

Listen 80
 
  ServerName localhost 
  DocumentRoot "Library/WebServer/Documents" 


Listen 8080
 
  ServerName www.test.com 
  DocumentRoot "Library/WebServer/Documents" 


Listen 8081
 
  ServerName www.test2.com
  DocumentRoot "Library/WebServer/Documents" 

Now, with the above, it is not necessary to alter /etc/hosts, right? After toggling WebSharing Off/On, and entering the URL, 'http://www.test.com", I get the message, "The specified server could not be found." What have I done wrong?

login or register to post comments

Re: Tried Both, having trouble

Submitted by bobdavis on October 7, 2001 - 07:08.

The method I outline is for developing multiple sites on a single machine. The problem is that your httpd.conf doesn't have anything to do with how domain names are resolved.

Additionally, adding Listen directives just does that - listens. Apache won't look at the port and determine what the server name is based on that, unles you're doing port based virtual hosts.

You still need to add the domain name in NetInfo Manager (which is a tool for changing the information that /etc/hosts would have in it in addition to all of the other things it does), and you still need to create the virtual hosts. That's just how Apache works.

To get www.test.com to resollve to something, it has to show up in either NetInfo, or in your DNS server. If it doesn't, you'll get the "server not found error".

If you want to see if your changes to httpd.conf are valid, there's a command line tool for apache that will do it for you. Just type this in the terminal:

apachectl configtest

As it is, I don't think your httpd.conf is valid like that. Try setting up the virtual hosts and adding the domain info into NetInfo Manager. Feel free to drop me a note if you have any questions.

login or register to post comments

It works! Just one more thing...

Submitted by mjw8 on October 9, 2001 - 02:32.

Thanks for your help. Now, I'm trying to turn off PHP warnings. I've edited 'php.ini' in /usr/local/lib, and tried various error reporting options. None seem to have any effect at all. My latest attempt is as follows:

error_reporting = ~E_ALL
display_errors = Off

Any ideas on this one?

login or register to post comments

Trying to get multiple sites working...

Submitted by Sixshot on November 14, 2001 - 11:27.

As a *NIX / #ac OSX newbie, I've tried to get the tip from MetaFather shown above to get multiple test sites running and accessable from an external machine, but can't seem to get it working. Do you also have to include the port settings in the NetInfo settings?

I have two symbolic links in my /Library/WebServer/Websites to my Home directory Users/william/Sites/site1 and site2. Everything works fine when I don't use port numbers, but as soon as I change it in the httpd.conf file, I just get the localhost default file and apache doesn't follow the symbolic links anymore. Here's my httpd.conf file:

#Change    Leave this one alone - it makes sure that localhost works

Listen 80
&ltVirtualHost 127.0.0.1&gt
 DocumentRoot /Library/WebServer/Documents
 ServerName localhost
&lt/VirtualHost&gt

#    Add new Hosts here for development

Listen 9000
&ltVirtualHost 127.0.0.1:9000&gt
DocumentRoot /Library/WebServer/Websites/site1
ServerName www.site1.test
&lt/VirtualHost&gt

Listen 9010
&ltVirtualHost 127.0.0.1:9010&gt
DocumentRoot /Library/WebServer/Websites/site2
ServerName www.site2.test
&lt/VirtualHost&gt


Include /private/etc/httpd/users
Anyone have the time to set me straight? Also, what do I need to do to get cgi scripts going from these directories? Thanks very much for any help.

login or register to post comments

IT Worked, But I Don't Have Permission

Submitted by hostile17 on December 13, 2001 - 16:57.

I followed the instructions in the article above to the letter, as far as I can tell, and I now have a www.fake.site at another location.

The only trouble is, I don't have access to it.

I get the message "you don't have permission to view www.fake.site".

I tried changing that directory using chmod 775 but that didn't help.

Anyone got any ideas?

login or register to post comments

You only need the second entry

Submitted by dayglow on December 28, 2001 - 04:24.

The tutorial was helpful, but the httpd.conf file in the OS X version of Apache already contains the info for localhost to work correctly.

You only need to enter the second VirtualHost in Section 3

# Add new hosts here for development <VirtualHost 127.0.0.1> DocumentRoot /Library/WebServer/Documents/path/to/files ServerName www.test.site </VirtualHost>

login or register to post comments

Annoying lookup problem with DHCP and NetInfo

Submitted by cmartin on April 30, 2002 - 11:40.

Great article!... I'm a new Mac convert (thanks to OSX) and the NetInfo manager is a little different than what I'm used to in other Unixes. This article was exactly what I was looking for.

Came across a network configuration that may be causing some problems for some...

I'm on a powerbook, so I'm constantly switching between networks at home, office, and the road. I initially set-up everything while on the road, directly connected to my internet provider and had no problems.

At home, when I tried accessing my virtual pages it reported an error. My home network has a FreeBSD gateway to the Internet running Natd and DHCPd. The virtual server I set up on my Mac was "www.test.site", and when I tried pinging that hostname, it returned the address of my FreeBSD Gateway. When doing a 'nslookup www.test.site', it returned a hostname:

   'www.test.site.myinternalnet.com'

Somehow, my Internal domain name was being added to any unresolvable (DNS) hosts and bypassing the NetInfo database...

I turned off my network interface on my mac (ifconfig en0 down) and tried accessing my 'www.test.site'... It worked! But it would suck if I'd have to disconnect from the network whenever I wanted to work on my site.

I looked at my FreeBSD Gateway's dhcpd.conf(ig) file and noticed a line:

   option domain-name "myinternalnet.com";

Evidently this was the reason why my mac was adding on the domain name, for when I commented out this line, restarted dhcpd, renewed my DHCP lease on my mac, everything works fine.

Those of you having problems accessing your virtual hosts should first try pinging the virtual hostname, verifying that the address is 127.0.0.1 (localhost) and not some other host.

I'm looking into lookupd (man lookupd) and how to change its default ordering from CacheAgent, DNSAgent, NetInfoAgent, to CacheAgen, NetInfoAgent, DNSAgent with my original DHCPd configuration, but no luck yet...Maybe I need to flush my lookup Cache, but the reordering of my lookupd seems to have no effect. The myinternalnet.com domain is still added onto the end of the virtual hostname. Any help/tips would be appreciated.

Hope this helps the few that were getting those errors. :)

- Chris

login or register to post comments

Re: Annoying lookup problem with DHCP and NetInfo

Submitted by cmartin on April 30, 2002 - 12:37.

Ok, figured it out...Here's how to reorder name lookups in lookupd:

*USE AT YOUR OWN RISK: READ 'man lookupd' FIRST!*

Summary: As root, I created the directory /etc/lookupd, and created two files within that directory named 'global' and 'host' with the new lookup orders, and then restarted lookupd...

% su -
# mkdir /etc/lookupd
# cd /etc/lookupd
# echo "LookupOrder CacheAgent NIAgent NILAgent" > global
# echo "LookupOrder CacheAgent NIAgent DNSAgent NILAgent" > hosts
# /System/Library/SystemConfiguration/Kicker.bundle/Resources/restart-lookupd

That did it for me...now whatever network I connect to, my virtual hosts will resolve correctly.

Cheers!
-Chris

login or register to post comments

another way possible?

Submitted by joon on June 1, 2002 - 18:31.

I'm very new to apache and unix but there is something that caught my eye and I am curious if it's possible to do.

Would it be possible to use some of the directives from the mod_alias module to trick a test site that its root is way inside a sub-directory? Away from the real root specified in the .config files so root links in the test site doesn't go there. For example on my machine, I have all my projects inside different folders and I let auto indexing take care of displaying the sub-folders. -I also modified how it looks by using CSS and HEADER.shtml files but that's another story.- The directives under mod_alias would have to sit inside an .htaccess file for the root -I think- of each site so the links and scripts would know it's relative root. This way, it shouldn't be necessary to remember odd port numbers and host names or any potential conflicts. Just drill down the auto indexed listings to get to the test site.

I'm trying to learn how apache works but I still don't know enough to test it out on my own. If it's possible, would it be a good idea? Would there be problems with web apps like message boards and scripts requiring a host name? I'd like to stay away from modifying netinfo and .conf files everytime I have a new project.

Thanks,
-joon

login or register to post comments

sorry! previous post won't work. :(

Submitted by joon on June 1, 2002 - 19:22.

Sorry about the previous post. Looks like the context for 'Alias' and 'ScriptAlias' have to be in the server config or virtual host. Completely kills the purpose of my last post.

I'm learning and I have a long ways to go.

Still wish there was an easier way without modifying .conf files or NetInfo for every project. Looks like I'll be virtual hosting my sites.

-joon

login or register to post comments

Web Server Error

Submitted by tom7711 on June 5, 2002 - 06:25.

I have setup the following files so that I can develop web sites but when I look at the web server status it gives me the following reply. My sites do work, but why am I getting this message? Could someone help me! PLEASE. SETUP: Mac OS X Server 10.1.4 Server Host Name: firebase Server IP address: 192.168.1.10 Subnet Mask:255.255.255.0 Router: 192.168.1.1 WEB SERVER STATUS [Wed Jun 5 10:33:44 2002] [warn] module mod_hfs_apple.c is already added, skipping [Wed Jun 5 10:33:44 2002] [warn] module mod_redirectacgi_apple.c is already added, skipping [Wed Jun 5 10:33:44 2002] [error] VirtualHost 127.0.0.1:0 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results [Wed Jun 5 10:33:44 2002] [error] VirtualHost 127.0.0.1:0 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results [Wed Jun 5 10:33:44 2002] [error] VirtualHost 127.0.0.1:0 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results /usr/sbin/apachectl start: httpd started /usr/sbin/webperfcachectl start: webperfcache started WEB SERVER SETUP Name : www.bombich.dev IP Address : 127.0.0.1 Port : 80 Web Folder : /Library/WebServer/www.bombich.dev Default document name : index.html Name : www.macsolutions.dev IP Address : 127.0.0.1 Port : 80 Web Folder : /Library/WebServer/www.macsolutions.dev Default document name : index.html NETINFO SETUP ip_address 127.0.0.1 name www.bombich.dev serves ./local ip_address 127.0.0.1 name www.macsolutions.dev serves ./local HTTPD.CONF DocumentRoot /Library/WebServer/Documents ServerName localhost DocumentRoot /Library/WebServer/www.macsolutions.dev ServerName www.macsolutions.dev DocumentRoot /Library/WebServer/www.bombich.dev ServerName www.bombich.dev

login or register to post comments

RE: Trying to get multiple sites working...

Submitted by gt_73_dump on July 16, 2002 - 13:33.

I am very new to all of this, but.... i think i remember reading that apache looks for hosts/vhosts from the bottom up. so, might it be site2, the site1, then localhost ? ( written backwards so to speak )

login or register to post comments

Web Server Not Restarting

Submitted by lordleiter on December 2, 2002 - 17:38.

I have gone through all of the steps and followed them to a "T". The trouble is that when I try and restart Personal Web Sharing, I get the message "Web Sharing starting up...", but it never seems to start up. I don't seem to be having any trouble with the Netinfo Manager, for when I create new "machines" they all point to the root level as described in the instructions. However, when I add the tags to the httpd.conf file, that is when the Personal Web Sharing won't restart. Even if I try to only have a localhost:
# localhost
<VirtualHost 127.0.0.1>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>
it won't restart. I am running 10.2. Has something changed since this article was written. I am at whits end.

login or register to post comments

httpd.conf reads only first VirtualHost def

Submitted by ievins on January 3, 2003 - 18:31.

This article was exactly what I was looking for--I was so pleased to find it!

Unfortunately, it seems these instructions only get me halfway there: adding new localhost defs to NetInfo works swimmingly, but Apache appears now to read only the first VirtualHost def in httpd.conf, whatever it is. (I thought perhaps the above suggestion about reversing the order would help me, but it doesn't.)

I am just trying for simplest case scenario:

<VirtualHost 127.0.0.1>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot /Users/me/Sites/sitename
ServerName local.sitename
</VirtualHost>

With the above defs, I get the localhost webroot for both localhost and local.sitename. If I reverse their order in httpd.conf, I get the local.sitename webroot for both. If I leave one and comment out the other, I get the remaining one for both. If I add another local site, then all three point to whichever is defined first in httpd.conf.

Any ideas about what could be going on here? Have I done something stoopid? I'm running 10.2 on a PowerBook G4, with Apache 1.3.

login or register to post comments

Answer for my above question

Submitted by ievins on January 12, 2003 - 18:46.

In case anyone else runs into the problem I described above on 1/3, Bob has kindly pointed out that I omitted one step of his instructions: "Uncomment the line that reads #NameVirtualHost * and change it to NameVirtualHost 127.0.0.1"

I wouldn't post my embarrassing explanation here were it not for the fact that it might save someone else the same trouble later.

login or register to post comments

BIG THANKS !!!

Submitted by anathema on January 16, 2003 - 14:34.

Thanks for this articel! I was looking around for days and now it works!!!!

This is a great article, nice to understand and correct (except of the little NameVirtualHost thing). I red a lot of articles and manual sites but always the NetInfo part was missing. So I'm happy that I found this article now.

I made my 'serious' work with Linux until now and I used the mac for the fun things - and now I'm happy that I can use the nice OS X for both.

have a nice day
anathema

login or register to post comments

Everything to a "T" - "can't find server"

Submitted by timware on March 25, 2004 - 11:24.

Using 10.3.3 - G4 In Netinfo Mgr: duplicated "localhost" renamed copy: Property: www.scgc.site Value(s): localhost Terminal: Edited httpd.conf Uncommented #NameVirtualHost *:80 Now says: NameVirtualHost 127.0.0.1 DocumentRoot /Library/WebServer/Documents ServerName localhost # Add new hosts for site development DocumentRoot /Library/WebServer/Documents/scgc ServerName www.scgc.site Restarted Apache The site's files are as specified above in the DocumentRoot value When trying to access http://www.scgc.site in browser, get "Safari can't open the page 'www.scgc.site/' because it can't find the server 'www.scgc.site' What am I doing wrong? Need guidance asap! Thanks. Tim

login or register to post comments

Everything to a "T" - "can't find server"

Submitted by timware on March 25, 2004 - 11:26.

Using 10.3.3 - G4

In Netinfo Mgr:
duplicated "localhost"
renamed copy: Property: www.scgc.site Value(s): localhost

Terminal: Edited httpd.conf
Uncommented #NameVirtualHost *:80
Now says: NameVirtualHost 127.0.0.1


DocumentRoot /Library/WebServer/Documents
ServerName localhost


# Add new hosts for site development


DocumentRoot /Library/WebServer/Documents/scgc
ServerName www.scgc.site


Restarted Apache

The site's files are as specified above in the DocumentRoot value

When trying to access http://www.scgc.site in browser, get

"Safari can't open the page 'www.scgc.site/' because it can't find
the server 'www.scgc.site'

What am I doing wrong? Need guidance asap! Thanks.

Tim

login or register to post comments

adjustments for 10.3.3

Submitted by maine_iac on March 28, 2004 - 08:54.

Hello all, bobs article is really great and saved me a lot of time!! ;-)

but at least for my system under panther (10.3.3) : ServerName must be in a line above DocumentRoot

NameVirtualHost 127.0.0.1


     ServerName www.mytestsite.dev
     DocumentRoot /whatever/directory/you/choose

Hope this can be of any help for others!!

login or register to post comments

Permissions

Submitted by Vic_Dicara on September 8, 2004 - 19:48.

Hostile 17 posted a problem about "You Don't Have Permission to View www.fake.com" Don't forget that you also have to setup other settings for your new server... for example, make sure you have something like

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from All

login or register to post comments

Do virtual hosting the EASY way

Submitted by patrickg on September 14, 2004 - 17:40.

A while back, I wrote a script that has become invaluable to me, my coworkers, and thankfully, many others tool.

For example, to add a virtualhost named "www.test.site", you would run:

sudo /path/to/virtualhost.sh www.test.site

Just follow the instructions, and in a few seconds, you'll be up and running. I recommend rolling back to your original httpd.conf just to be safe, but it doesn't look like anything Bob Davis has recommended to change will interfere with how my script works.

Read about it on my site: http://patrickg.com/virtualhost.

login or register to post comments

Makes perfect sense - but doesn't seem to work

Submitted by Kurt on December 25, 2004 - 22:21.

Can't get it to work.

Just a review:

1) I opened netinfo
2) Selected machines/localhost
3) Clicked the lock and entered the password for access
4) Selected the "Duplicate" Icon
5) Clicked "duplicate" in confirm dialog
6) Selected the "localhost copy" string and changed it to "www.test.site"
7) Clicked on localhost
8) dialog - save
9) dialog Update this copy

At this point, typing www.test.site into my browser is supposed to get me the same thing as localhost

localhost gets me my index.html page
www.test.site gets me an error pop up that reads:
(continued on next rock)

login or register to post comments

(next rock)

Submitted by Kurt on December 25, 2004 - 22:30.

Safari cant find the server
Safari cant open the page http://www.test.site/ because it cant find the server www.test.site.

I'm running Mac OS X 10.3.7 on a G4/450.

I'd really love for this to work so my production and development sites can be identical. (As it is, the development site always has that extra level... what a pain.)

Thanks. P.S. MAN!
What is with the quotes and apostrophes? I thought I had run up against a space limitation per comment, but it was just the software cutting off all comments after an apostrophe (hence cant) or a quote (which is why all the URLs are unquoted). BUG ALERT!

login or register to post comments

Bug alert?

Submitted by MartinB on December 28, 2004 - 15:38.

Content being cut off after quotes tends to happen when you use smart or curly quotes, as opposed to simple inch/foot marks. Thus ' and " are fine (the latter is much better when escaped as &amp;quot; of course: ").

Cheers, Martin
On behalf of evolt.org

login or register to post comments

Virtual hosts when working offline?

Submitted by ievins on January 4, 2005 - 15:16.

I find that when I'm away from my Net connection, my Apache virtual hosts don't work. Seems to me that a Net connection should be irrelevant to localhost performance. Is there an easy config fix for this problem?

login or register to post comments

Permissions problem

Submitted by overkenny on February 24, 2005 - 04:33.

Followed the article and now have a virtual host working. e.g. http://my.test.site only problem is that now http://localhost/ returns a 403 error: Forbidden You don't have permission to access / on this server. Apache/1.3.33 Server at localhost Port 80 i can still get to http://localhost/~myusrname and i have run repair disk permission so i think they are ok any ideas? thanks kenny

login or register to post comments

Permissions Problem

Submitted by MartinB on February 24, 2005 - 06:47.

In Terminal, cd to the directory in question. Then do

chmod 655 ./

to enable directory browsing in that directory.

Alternatively, put an index.html file in there and see what happens.

login or register to post comments

Great... now what about Virtual PC

Submitted by pixelguru on February 24, 2005 - 08:37.

This is a great article, and with the help of the posts, I now have multiple virtual hosts up and running. Works great! However... I use Virtual PC for testing, and it gives me a "page unavailable" error when I try to access any of my new virtual hosts OR 127.0.0.1. Any ideas? Do I need to do the same sort of thing I did to NetInfo somewhere inside Windows XP? ...or should I just continue my efforts to stop every PC user in the world from using IE so I no longer have to test with it?

login or register to post comments

Permission problems

Submitted by overkenny on February 25, 2005 - 00:58.

Hi martin, my files are in the standard Documents folder and I have run repair file permissions on it so it is set at the standard 775. I have also put a index.html file inside it but I still get a 403 error :(

login or register to post comments

Directory Browsing

Submitted by MartinB on February 25, 2005 - 01:30.

Ah, you'll probably not have enabled directory browsing in the config. In that host's config put

<Directory /Library/WebServer/Documents/>
Options Indexes FollowSymLinks
</Directory>

Take a look at this documentation for a full list of Directory options.

login or register to post comments

pixelguru's virutal PC

Submitted by Vic_Dicara on February 25, 2005 - 05:09.

Hi Pixelguru... I have a similar problem. To the best of my knowledge there is no way to set up windows to use the Virutal Hosts names - but I remember there used to be a hosts file somewhere in windows where you could specify your own domain names. When I finally recall where the heck this was, I will try sticking one of my development names in that list and see if it works but for now... Here is what I do: I edit the apache httpd.conf file so that the default server is the particular virutal server that I want to test from Windows - you know, the one that, out of the box, points to /Library/Webserver - I change that to point to the right place and then from windows I can hit the website by just calling the ip of the osx machine.

login or register to post comments

VPC now working too!

Submitted by pixelguru on February 25, 2005 - 08:11.

Got it... I just had to stop and think a second. Went back into my httpd.conf file and duplicated all my virtual host listings. I changed the duplicate listings to point to my local static IP address (192.168.0.2, not 127.0.0.1). That way, VPC (with it's modified hosts file) looks for www.mytestsite.test at 192.168.0.2, and Apache picks up from there routing that IP to /Users/me/Sites/mytestsite. Excellent! Now I suppose I could be even neater about it and change the NetInfo settings I originally messed with to my local IP instead of 127.0.0.1 so that one IP would work for both OSX and VPC, and I wouldn't need to have duplicate listings in my httpd.conf file.

login or register to post comments

VPC - do what?

Submitted by smd69 on March 4, 2005 - 07:19.

I'm thoroughly confused now - have the same problem, attempting to test in IE on VPC with sites running on PHP, etc. Any chance you might cover the steps on that? One of the BIGGEST hassles is that, when installing various "self-installing" PHP scripts, the scripts automatically "guess" their http locations - so it'd be a LOT easier to be able to set up the virtual hosts that would work from different machines on the same LAN and be done with it. Sorry, just a newbie trying to follow a thread and getting in over his head. Thanks for any help/advice. Also, I thought I'd run into a script written by someone to manage this problem? Can't remember where it was.

login or register to post comments

Here's the script that does all of this

Submitted by smd69 on March 4, 2005 - 07:26.

Here's a script that automatically sets this up:
http://patrickgibson.com/utilities/virtualhost/

login or register to post comments

Not pointing to defined location

Submitted by warmac on October 26, 2005 - 23:59.

I tried the above example however, it does not point to the location defined in the http file i used /Library/WebServer/Documents/newdir/index.html it still points to the main Documents/index.html It's the same set up in your example only I added the /index.html to the 2nd one did I miss anything ?

login or register to post comments

That did the trick

Submitted by warmac on October 27, 2005 - 00:49.

once i changed it that worked how does having a virtual host called http://www.test.site/ relate to creating a virtual domain, can we do http://www.mydomain.com/ or could we simply use whatever virtual name we make up as the domain for others to access our site ? I know this was not meant for actual site more for testing but seems like it could be used as a URL to access a site on the mac

login or register to post comments

Tiger issues

Submitted by warmac on November 6, 2005 - 08:24.

updated to 10.4 tiger and tried to setup a virtua host again, got it working on panther but on tiger for some reason it's not working forget the secret, are we suppose to change the order from doc root servername to servername docroot ? ? I can't even get local host 127.0.0.1 to show up

login or register to post comments

SMB Mount and virtual host

Submitted by roscoeh on November 6, 2005 - 20:17.

I am new to the mac os and have a shared folder on my windows pc (wwwroot) which contains all my sites & i can see and modify on my mac.

I now would like to run the shared php files on the mac so I caa test in safari/ie but have no idea how to do this. I followed the tutorial and ran the new host which worked and then tried adding a second user directory..is this possible?

Do I change the virtualhost or the user directory and how do I achieve this for my networked wwwroot folder?

Mu current folder is the default /Users/~rosshulford/Sites.

Thanks,

Ross

By the way it is PHP5 and Apache 1.3

login or register to post comments

No need to use netinfo manager

Submitted by warmac on November 18, 2005 - 23:25.

i got all my setup to work, the instructions above says to use netinfo manager to duplicate localhost, you don't have to do that and I hear it's highly recommended to stay away from netinfo manager. I removed all the duplicates in netinfo and just adjusted the virtual host in apache and that did the trick, not sure why the above article said to use netinfo I never had to use it in the first place. As long as you do the setup in apache you'll have the hosts set up

login or register to post comments

Netinfo not necessary

Submitted by warmac on November 18, 2005 - 23:34.

The above says to use netinfo you don't have to Just set virtual host up in apache and it will work

login or register to post comments

Shortcut when working on one dev site

Submitted by pvwinter on November 23, 2005 - 09:29.

Simple shortcut if you're working on one dev site only and want to bypass editing the Apache Config file: in the Finder go to your Hard Disk/Library/WebServer/Documents/ folder, remove or backup the default docs and replace them with your test.site files.

login or register to post comments

How to...

Submitted by netmorix on November 27, 2005 - 10:24.

set a directory in the apache.conf, which leads to an external harddisk.. cause I'm working in the office and the home office, some of the webprojects are on my external harddisk (in OSX visible as DATADISK). I'm just switching from Windows to MAC for development - so sorry for my silly questions...

login or register to post comments

Enabling virtualhosts over LAN

Submitted by imagecrisis on February 19, 2006 - 16:03.

If your setup is OS X Apache and you are testing sites on a remote PC. On the PC edit the hosts file.

Windows 95/98/Me c:\windows\hosts

Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts

Windows XP Home c:\windows\system32\drivers\etc\hosts

Example:
OS X server 192.168.0.2 (ensure in the httpd.conf that it will listen to 192.168.0.3 requests)

testing PC 192.168.0.3

in the HOSTS file add:

192.168.0.2 my.test.site

This will enable access to the my.test.site virtualhost that is setup on OS X

login or register to post comments

How to get another machine to connect?

Submitted by handycam on March 1, 2006 - 15:08.

You say "Example: OS X server 192.168.0.2 (ensure in the httpd.conf that it will listen to 192.168.0.3 requests)"

Ensure how, exactly?

What do I change in my httpd.conf so that my os x station will listen to requests from my pc laptop?

I have:

Listen 8080

<VirtualHost 127.0.0.1:8080>
ServerName local-latte
DocumentRoot /Users/Shared/WORK/myclient/html
</VirtualHost>

My mac's IP address is 192.168.1.22. So on the PC, I type 192.168.1.22:8080 in the address bar, but I get nothing.

Note that If I type 192.168.1.22 in the address bar, I get the default apache root page located in /Library/Webserver/Documents as expected.

But I need to be able to access other client sites I keep in my various directories. I can access them no problem from the Mac itself. http://localhost:8080 gets me the site above.

I'm so close, just need the one more piece!

login or register to post comments

Don't forget your Firewall

Submitted by amontague on March 1, 2006 - 17:31.

I've been working on this for two days solid. I could view www.test.site:8080 from the computer with the test site - but not from any other computer on the network. The problem was the Firewall. On the test computer:

1. Go to System Preferences -> Sharing -> Firewall.
2. Click on New...
3. Click on the Port Name pop-up list and choose Other
4. Give the a name such as "website testing" in description
5. Enter your port number such as 8080 in TCP Port Number(s)
6. Click OK and you're set

You should now be able to log into your site on other computers on your network

login or register to post comments

Cannot see second site from the net

Submitted by nicholasmk on May 4, 2006 - 07:42.

Hi There. I have enabled virtual hosting on port 8080 and I can see the website locally. Once outside the LAN, no go. I have a Linksys Router with port 8080 forwarded to the local machine. I have opened port 8080 on the OS X firewall. What I am missing?

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.