4

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!

Jens
  • 147
  • 2
  • 9

4 Answers4

5

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"
    ))
)
sybreon
  • 7,405
  • 1
  • 21
  • 20
  • How should we do to load multiple variable from the environment? Is it possible to give a file containing all the `export` ? – Jav Nov 23 '15 at 17:10
2

Any environment variable could be exposed to the php via setenv module
e.g.:

server.modules += ( "mod_setenv" )
setenv.add-environment = ( "PATH" => env.PATH )
zippie
  • 21
  • 1
1

You could build a wrapper script for the program, add your environment settings to it, and run the wrapper script instead of the original program.

#!/bin/sh
ENV=... /path/to/program
derchris
  • 471
  • 2
  • 7
0

It might work if you put it to lighttpd init script:

export MYVAR="something"

on top of the script or inside start() function

rvs
  • 4,125
  • 1
  • 27
  • 31