Forum Moderators: coopster

Message Too Old, No Replies

Serving Multiple Sites From One Server

A couple of hints

         

ukgimp

10:22 am on Apr 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know that this is strictly and apache thread but most people wish to know how to develop multiple php sites so I put it in the php forum

#######

A while back I asked about creating some sort of alias for developing multiple sites, however I was using absolute urls which was messing things up somewhat. Well last week I found a good soloution:

Virtual Hosts

You will need to add your names in your windows config host file

127.0.0.1localhost red blue

You can find this file here :
C:\WINDOWS\system32\drivers\etc\hosts

Where red and blue will be virtual hosts

Now if you are running some sort of emulator or even linux you will need to edit your httpd.conf file:

You need to add <VirtualHost> container directives

Eg

<VirtualHost *>
ServerName red
ServerAdmin dave@red.com

DocumentRoot C:\red\root\
ErrorLog C:\red\logs\error.log
CustomLog C:\red\logs\access.log combined
</VirtualHost>

<VirtualHost *>
ServerName blue
ServerAdmin dave@blue.com

DocumentRoot C:\blue\root\
ErrorLog C:\blue\logs\error.log
CustomLog C:\blue\logs\access.log combined
</VirtualHost>

You can put just about anything within the containers as you might have on your server. So you could put for following in red to make cgi the default page.
<Location />
DirectoryIndex index.cgi
</Location>

Now when you fire up apache again you should be able to see

The following two addresses

[red...]
[blue...]

Wondering what has happened to the localhost or 127.0.0.1, well in the httpd.conf the first virtual host in the list will be considered to be the most important.

Hope that helps a bit. Cheers

hakre

2:24 pm on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



whoa, that's nice. good to know it rests here in the php forum. using virtual hosts on the development side (using win32 for this, too) is quite a good solution. .htaccesses can be tested better etc. pp.

nice one!

--hakre

ergophobe

3:19 pm on Apr 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good idea. I serve up multiple sites from a single server for live sites, but I hadn't thought of just adding a virtual host for each site I'm working on on my local machine.

I just use a config file so the paths resolve themselves by changing one setting, but I could just change one setting in the httpd.conf instead.

Tom

Francis

6:11 am on May 4, 2004 (gmt 0)

10+ Year Member



This is one interesting thread and I was meaning to try it out. However, I don't have the etc\hosts directory on my Win98 machine. I do have Apache, PHP and MySQL running. Can you help me with my problem? Thanks.

Brett_Tabke

7:07 pm on May 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Ya, it is also nice to do the above with dual host files.

I run a hosts file that contains ALL of my online sites referenced on different local ips. For example:

hosts:

127.0.0.10 webmasterworld.com
127.0.0.11 searchengineworld.com

and on and on.
Then I run a conf file tied to that specific ip:

<VirtualHost 127.0.0.11>
DocumentRoot /www/searchengineworld
ServerName www.searchengineworld.com
ServerAdmin webmaster@searchengineworld.com
ScriptAlias /cgi-bin/ /www/searchengineworld/cgi-bin/
TransferLog logs/sew-access.log
ScriptLog logs/sew-scripterror.log
</VirtualHost>

Add in a simple batch file with a link on my desktop that swaps out the fake hosts file for the real one:

----------------
@rem remove the old file
del c:\windows\hosts
@rem install new
copy c:\windows\hosts.loc c:\windows\hosts
@rem lets go apache
c:\apache\apache.exe
rem done
----------------

And now, I have 100% seamless production in the browser. eg: type in www.webmasterworld.com into my browrser and *presto* up comes WebmasterWorld off of my local disk.

It sure makes perl delevelopment a snap.

btw: this isn't a php thread, it is a PERL thread. lol