I’m migrating a perl cgi script from linux to windows IIS server 2003 and see that there is no DOCUMENT_ROOT environment variable.
Some googling suggests I can hack it by stripping stuff off the end of $0 or cwd, but getting the site root should be a common task. Is there a better or standard way of doing this?
IIS doesn’t really have the notion of a document root in the same way with IIS, as each application is more or less self-contained and independent. For any request,
PATH_TRANSLATEDis usually a good base on which to build, it is set to the physical path name for the handling component set inPATH_INFO, and from that you can usually get to the file system locations using a little File::Spec navigation.There’s also a
SCRIPT_TRANSLATEDandSCRIPT_NAME, which may be closer to what you need. SCRIPT_NAME is essentially the host absolute URL (minus the scheme, host, and port) for script, andSCRIPT_TRANSLATEDis the corresponding physical file. I use theURIandURI::fileclasses, and methods to manipulate them, for some of these tasks.These will only be useful if your request is handled by the same application that serves files, but they do allow you do derive URLs which work. If you need the file system for the root application, the one mapped to “/”, and your script is not in the same root application, you will likely have to do some accesses to the IIS metabase (essentially the equivalent to
httpd.confand friends, but queryable) to find this out.