Search code examples
phpiis-7fastcgi

PHP FastCGI open_basedir restriction on IIS 7


I have two environments on one server, which are separated via EnvironmenteVariable. That part works like a charm (two FastCGI pools with open_basedir has been set up to ApplicationHost

<application fullPath="C:\path\to\php\php-cgi.exe" arguments="-d open_basedir=C:\path\to\webroot\ENV_DIR">

and related web.config

<add name="php" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\path\to\php\php-cgi.exe|-d open_basedir=C:\path\to\webroot\ENV_DIR" resourceType="Unspecified" requireAccess="Script" />).

Problem starts with open_basedir restriction for other folder(s) - like \\path\to\network\folder or C:\path\to\webroot\FOLDER (which is outside the environment folder). How to enable the access to these folder(s)?

Have tried:

  • separated php.ini files per environment with open_basedir="multiple;folders"
  • add multiple folders to web.config and applicationHost file to arguments like following:

'... open_basedir="C:\path\to\webroot\ENV_DIR;C:\path\to\webroot\FOLDER"'

Nothing seams to help.


Solution

  • Okay, found a solution. Maybe somebody else needs it as well. Instead of using open_basedir, use doc_root (IIS only, if memory serves, PHP option). Here are examples:

    applicationHost.conf file:

    <application fullPath="C:\path\to\php\php-cgi.exe" arguments="-d doc_root=C:\path\to\webroot\ENV_DIR">

    and related web.config

    <add name="php" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\path\to\php\php-cgi.exe|-d doc_root=C:\path\to\webroot\ENV_DIR" resourceType="Unspecified" requireAccess="Script" />

    In this way, you are able:

    • set up instance-based environment variables (.env under Linux);
    • able to include and/or use directories outside instance root folder.