doc_root outside IIS root?

Posted on 2005-03-06
Medium Priority
Last Modified: 2013-12-13
Dear all,

I have a website hosted on Apache; I develop, however, using IIS IIS 5.1 on Windows XP.

I want a generic template such that I can use both of (for example):
 * include("/home/mysite/public_html/includes/public.php");
 * <link rel="stylesheet" type="text/css" href="/stylesheets/public.css" />
(where /home/mysite/public_html is the root to my website on the live server).

This is fine on the live box, but I cannot replicate it locally - let the physical path to the local root directory be c:\mywebsite\home\mysite\public_html - if I set the IIS root directory to be c:\mywebsite, the PHP include works fine but the stylesheet link is wrong; if I set the IIS root directory to be c:\mywebsite\home\mysite\public_html the stylesheet link works fine but the PHP include breaks.

I thought about setting the doc_root in php.ini to c:\mywebsite and the IIS root directory to c:\mywebsite\home\mysite\public_html, but then IIS returns a 404 error whenever it tries to interpret a PHP page.

Any suggestions? - I don't particularly want to install Apache or start setting include paths every time I use PHP...

Many thanks in advance,

Question by:pdb086
  • 2
  • 2
LVL 11

Accepted Solution

matt_mcswain earned 1000 total points
ID: 13474191
Just use relative paths for everything. Unless there's files you're making available for download or something outside the document root.  Are you aware of the $_SERVER['DOCUMENT_ROOT'] variable?

Author Comment

ID: 13474842
That's what I'm doing at the moment; I want to do it like this so it can just be dropped into any page, but also so that if the page is moved to a different directory at any point it can cope with it; I don't really want to start trawling through code in future...
LVL 11

Expert Comment

ID: 13479412
Literally use:

include $_SERVER['DOCUMENT_ROOT'].'/includes/public.php';

Where the doc_root is either

and for web links literally use


or even better for links

<? echo 'http://'.$_SERVER['HTTP_HOST'].'/stylesheets/public.css';?>


Author Comment

ID: 13481674

Many thanks - I hadn't realised those variables were available to PHP - should have looked through phpinfo() more carefully, I guess - just goes to show that sometimes you do just need to state the obvious... :D

Just for the record, I develop ASP.NET/MS SQL on IIS; I'm perfectly competent at that, honest...

Thanks again,


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question