Forum Moderators: travelin cat
I need to be able to develop multiple sites where I can use root paths for includes, global navigation etc. (Example: /assets/images/img.gif) I've already created subfolders under Library/WebServer/Documents.
I THINK this maybe called virtual hosting and have found articles but they all say "Open Pico and add a virual host." Sorry but I am not UNIX literate so if this is my solution I will need a bit more instruction than that. :)
So I need two or more folders where I can type in an IP and the IP is treated as the root in the URL. (http://127.0.0.2/assets/images/img.gif maybe?)
Can anyone help me?
Open a terminal window and type the following:
sudo pico /etc/httpd/httpd.conf
Then enter your admin password. Congrats - you just opened the apache config file using the simple text editor pico.
Scroll through the config file using the arrow keys. Pretty everything is well commented there so you should easily find the virtual hosting parts. You can also search in pico. Look at the help / shortcuts at the bottom of the pico terminal screen (the black bar).
The official apache docs about virtual hosting can be found here:
[httpd.apache.org...]
You might also want to have a look at some of the past discussions about virtual hosting on apache here at WebmasterWorld: Apache Virtual Host [google.com]
Especially this thread may be helpful for you:
Setting up Virtual Hosting on Mac [webmasterworld.com]
cp /etc/httpd/httpd.conf /httpd.conf
I think I am missing something obvious — like I should be entering in an address where a * is or something. Let me try again by using my specific needs as an example so someone can reply with a specific example of code.
Note: This is only for local development purposes.
Ok I have Project1 and Project2 folder in /Library/WebServer/Documents/. I want to be able to type the ip 127.0.0.1 for Project 1 and I want to be able to type the ip 127.0.0.2 for Project2.
Or urls are fine too, like dev.project1.com and dev.project2.com.
Seems simple enough. :-D
P.S. I need this because the paths in the sites need to be root relative.
1) create a folder containing each of the sites
2) go to the bottom of /etc/httpd/httpd.conf, find "### Section 3: Virtual Hosts" and uncomment "#NameVirtualHost *:80".
3) a little further down you have a commented section between "#<VirtualHost *:80>" and "#</VirtualHost>". You'll need a copy of this section for each of your virtual websites in uncommented condition.
4) for each of your virtual websites you'll need to specify at least the "DocumentRoot" and "ServerName"
5) now you'll need to edit /etc/hosts: insert at line for each of your virtual websites at the end of this file - 127.0.0.1 ServerName
6) restart Apache
the easiest way to edit these two files is if you've got bbedit 7.* installed. it comes with a commandline tool so you can just enter 'bbedit /etc/httpd/httpd.conf' in the terminal.
[patrickgibson.com...]
guiroo, which do you hate more -- Unix headaches or spending $500?
[apple.com...]
There's also WebStar -- they're still around and promising to make everything easy for $300.
[4d.com...]