How to Set an Environment Variable for a Process Spawned by the Webserver

debianenvironment-variableslighttpd

In my setup (debian etch, lighttpd), one one my websites is calling a program for some image manipulation via PHP, I think. I'd like to change the behavior of this program by setting an environment variable, preferably without changing the web app.

How to do this? =)

Setting the environemt variable for all processes owned by the www-data user would be ok, too, but I am usure if an entry in, say, .bashrc(?) would be respected in this scenario.

Thanks!

Best Answer

Since you are using lighttpd fast-cgi, just set it using bin-environment within the lighttpd settings.

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server    = ( ".php" => 
    ((
            "bin-path" => "/usr/bin/php-cgi",
            "socket" => "/tmp/php.socket",
            "max-procs" => 2,
            "idle-timeout" => 20,

            "bin-environment" => ( 
                    "PHP_FCGI_CHILDREN" => "4",
                    "PHP_FCGI_MAX_REQUESTS" => "10000",

            ),

            "bin-copy-environment" => (
                    "PATH", "SHELL", "USER"
            ),
            "broken-scriptfilename" => "enable"
    ))
)