Richard Greenwood
Richard Greenwood

Reputation: 1004

setting and reading environment variables in IIS 10

I can not figure out how to set and read environment variables in Microsoft Internet Information Services (IIS) version 10. I have a Fast CGI app that requires environment variables. In previous versions of IIS I just set system-wide variables in the Windows "System Properties". However in IIS 10 my FCGI app isn't reading them. So my first question is if there are steps that need to be taken so that the IIS process can read system variables?

Alternatively, how do I set environment variables within IIS 10? This Microsoft site explains it but not in enough detail for me to get it working. Specifically, in what file and in which section do you put the <environmentVariables> section? The example XML and the command line example have name="Contoso" (see below) but what is that - the name of the application pool, or my FCGI app, or something else?

<applicationPools> <add name="Contoso" managedRuntimeVersion="v4.0" managedPipelineMode="Classic"> <environmentVariables> <add name="foo" value="bar" /> </environmentVariables> </add> </applicationPools>

Edit in response to Jokies Ding: MAP22 and PROJ_LIB are the two environment variables that I need. In C:\Windows\System32\inetsrv\Config\applicationHost.config I have:

    <applicationPools>
        <add name="DefaultAppPool" />
        <add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
        <add name=".NET v4.5" managedRuntimeVersion="v4.0" />
        <add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" />
        <applicationPoolDefaults managedRuntimeVersion="v4.0">
            <processModel identityType="ApplicationPoolIdentity" />
            <environmentVariables>
                <add name="PROJ_LIB" value="/gdal/bin/proj6/SHARE" />
                <add name="MAP22" value="/tetonwy/mapserv/main.map" />
            </environmentVariables>
        </applicationPoolDefaults>
    </applicationPools>

and

    <fastCgi>
        <application fullPath="C:\gdal\bin\ms\apps\mapserv.exe">
            <environmentVariables>
                <environmentVariable name="MAP22" value="C:\tetonwy\mapserv\main.map" />
                <environmentVariable name="PROJ_LIB" value="C:\gdal\bin\proj6\SHARE" />
            </environmentVariables>
        </application>
    </fastCgi>

and in a cmd window the environment variables are visible

C:\>set MAP22 MAP22=C:\tetonwy\mapserv\main.map C:\>set PROJ_LIB PROJ_LIB=C:\gdal\bin\proj6\SHARE

So it seems like I've got the variables set all over the place but the app isn't seeing them. C:\gdal\bin\ms\apps\mapserv.exe is the FastCGI app that isn't seeing the environment variables. It's a compiled C program that I have used in previous versions of IIS.

Upvotes: 0

Views: 6866

Answers (2)

geographika
geographika

Reputation: 6528

There is an issue with MapServer not reading environment variables on Windows when used through FastCGI.

This is resolved by applying https://github.com/MapServer/MapServer/pull/6304 which will be backported to the 7.x MapServer releases.

See Environment variables ignored using FastCGI and IIS #6289 for more details.

Upvotes: 1

Jokies Ding
Jokies Ding

Reputation: 3494

<environmentVariables> section is displayed as a collection under specific application pool.

You could find it in IIS global configuration file C:\Windows\System32\inetsrv\config\applicationhost.config. "Contoso" is the name of application pool.

I think read system-wide variable is still supported in IIS 10 and PHP FAST-CGI. I can get these configuration by running commandline SET in IIS PHP-CGI.

Could you post the code that you used to read the variable?

In some condition, Your application code require elevated permission. You could try to change application pool identity to local system and set Anonymous authenticated user to Application pool identity

Upvotes: 0

Related Questions