Possible Solution for Hosting Multiple PHP Sites with IIS

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
cdblakey
Forum Newbie
Posts: 2
Joined: Thu Apr 06, 2006 10:41 am

Possible Solution for Hosting Multiple PHP Sites with IIS

Post by cdblakey »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've noticed numerous posting for how to host multiple website using PHP and IIS and I have an answer; that works for me anyways. I'm running IIS 5.0 on a Windows 2000 Server.   I am hosting two websites with the same IP address but using different port numbers. I have two folders inside my web directory , let's say website_1 and website_2, with my index.php file located in my website_1 folder. My php.ini file is located in the WINNT folder where my doc_root is set to look in my website_1 folder. My index.php file uses the $_SERVER['HTTP_HOST']  variable to determine which website is being requested and loading the proper page. The code looks like this:

Code: Select all

<?php
$request = $_SERVER['HTTP_HOST'];     //store the requested web address

ereg(':[0-9]+', $request, $request);    //pull port number out of ip address
switch ($request[0])     
{
  case ':website_1_port' :      //if port number matches for website 1, load that site
  {
     //build start page of first website
  }
  case ':website_2_port':     //if port number matches for website 2, call a function listed in the website_2 folder to load that site
  {
     //call to function located in 'C:\web_directory\website_2\called_function.php' to build start page of second website
  }
}
?>
This is working great for me, and if anyone has any question or sees an inherent problem that I'm over looking please reply.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

thats makes a lot of sense/ you simply then just put like a header or something?but,if they are on diffrent ports,wats the point of this? why dont u use host headers in IIS?
cdblakey
Forum Newbie
Posts: 2
Joined: Thu Apr 06, 2006 10:41 am

Post by cdblakey »

I'm using SSL and IIS 5.0; host headers do not seem to get along very well with that combination. If you were to use host headers I suppose you could use the same HTTP_HOST variable though.
User avatar
t-cat
Forum Newbie
Posts: 12
Joined: Fri Apr 07, 2006 5:40 am
Location: South Africa

Post by t-cat »

I had an issue getting multiple sites under IIS 6 to use php.

I solved the problem by setting the docroot directive in php.ini to nothing.
Post Reply