Possible Solution for Hosting Multiple PHP Sites with IIS
Posted: Thu Apr 06, 2006 11:20 am
feyd | Please use
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]
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
}
}
?>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]