« Previous Next »

Thread: Separate PHP.ini for each website?

Last post 06-11-2009 2:53 PM by v-edsojo. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 04-21-2009, 11:35 AM

    Separate PHP.ini for each website?

    I'm trying to setup a website to use a different php.ini from the default that most websites use on the server. I can go to Internet Service Manager, SERVERNAME, FastCGI Settings, click Add Application, I use

    Full Path : c:\php\php-cgi.exe

    Arguments : -cd:\website2\

    This is telling php-cgi to find the ini file in d:\websites2

    The problem I'm having is I then go to the website, go to mappings, add the ModuleMapping of FastCGIModule but how do I tell it to use the unique configuration I gave it above?

    Only idea I can come up with is to copy php-cgi.exe to a unique folder or name it something else like php-website2.exe, but then I would have to remember to update that file each time I updated php to the latest version unless I used mklink to create a symbolic link.

    Is that the only way to differentiate the mappings between the website and the applicationhost.config fastcgi mappings, thru using a unique filename or path?

  • 04-21-2009, 1:34 PM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 863

    Re: Separate PHP.ini for each website?

    Hi,

    FastCGI section has fullPath and arguments as key. Both values combined but separated by '|' (pipe character) is treated as key. You need to specify this key in handlers section. In you case, you will give "c:\php\php-cgi.exe|-cd:\website2" as the scriptProcessor in handler mapping.

    Thanks,
    Kanwal

    Follow me on twitter at http://twitter.com/kjsingla
  • 04-21-2009, 4:11 PM In reply to

    • v-edsojo
    • Not Ranked
    • Joined on 09-22-2008, 10:29 AM
    • Venezuela
    • Posts 10

    Re: Separate PHP.ini for each website?

    Hi.

    The problem is that for php compiler you have to use is -c <php.ini_file_path> but it only works for php.exe not for php-cgi.exe

    I had to use php.exe instead of php-cgi.exe and in my website´s handler mapping i configured php extension using "C:\<php_root>\php.exe"|-c <new_php.ini_file_path>

    You can also test php-cgi by console putting the following command:

    C:\<php_root>\php-cgi -c <php.new_ini_file_path>

    If it works, it will works on IIS.

    - -
    Eduardo Sojo
    http://eng.eduardosojo.com
    Caracas - Venezuela
  • 04-21-2009, 5:51 PM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 863

    Re: Separate PHP.ini for each website?

    Instead of using -c switch, you can use PHPRC environment variable to specify the path from where ini file should be picked. Read how to set per site ini file here. Search for PHPRC.

    Thanks,
    Kanwal

    Follow me on twitter at http://twitter.com/kjsingla
  • 04-22-2009, 12:44 PM In reply to

    • v-edsojo
    • Not Ranked
    • Joined on 09-22-2008, 10:29 AM
    • Venezuela
    • Posts 10

    Re: Separate PHP.ini for each website?

    You´re right Kanwal...

    Part of the explanation on iis.net (http://rurl.me/ws85):

    Specifying php.ini location

    When the PHP process starts it determines the location of the configuration php.ini file by using various settings. The PHP documentation provides detailed description of the PHP start up process. Note that one of the places where PHP process searches for php.ini location is the PHPRC environment variable. If PHP process finds a php.ini file in the path specified in this environment variable then it will use it, otherwise it will revert to default location of php.ini. This environment variable can be used to allow hosting customers to use their own versions of php.ini files.

    For example if there are two websites: website1 and website2; located at the following file paths: C:\WebSites\website1 and C:\WebSites\website2 then the php-cgi.exe process pools in the <fastCgi> section of applicationHost.config can be configured as below:

    <fastCgi>
        <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\Websites\Website1">
            <environmentVariables>
                <environmentVariable name="PHPRC" value="C:\WebSites\website1" />
            </environmentVariables>
        </application>
        <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\WebSites\Website2">
            <environmentVariables>
                <environmentVariable name="PHPRC" value="C:\WebSites\website2" />
            </environmentVariables>
        </application>
    </fastCgi>

    This way website1 can have its own version of php.ini in the C:\WebSites\website1, while website2 can have its own version of php.ini located in C:\WebSites\website2. This configuration also ensures that if there is no php.ini found in location specified by PHPRC environment variable then PHP will fall back to using the default php.ini file located in the same folder where php-cgi.exe is located.

    --------------------------------------------------------------------------------------------------------------------------------------

    - -
    Eduardo Sojo
    http://eng.eduardosojo.com
    Caracas - Venezuela
  • 06-11-2009, 2:53 PM In reply to

    • v-edsojo
    • Not Ranked
    • Joined on 09-22-2008, 10:29 AM
    • Venezuela
    • Posts 10

    Re: Separate PHP.ini for each website?

    Hi, here is an article that explains how to work with differents php.ini in IIS7:
    http://eng.eduardosojo.com/differents-phpini-config-file-for-each-websit

    Regards,

    - -
    Eduardo Sojo
    http://eng.eduardosojo.com
    Caracas - Venezuela
Page 1 of 1 (6 items)
Microsoft Communities