I need to set some environment variables for my PHP application, but when I use
I've also tried using
This question is marked "community wiki".
For security, we use suexec to ensure that your PHP and CGI scripts run as your user, and not as the system apache user. As an additional security measure, suexec wipes out environment variables before your script is executed.
To work around this, you need to wrap your scripts in a handler that sets its own environment prior to calling the actual script. suexec has already cleaned the environment when it runs the wrapper, so any environment variables set by the wrapper will be present when it calls the actual script being run.
Here's a real world example:
You've got a PHP 7 application "app_name" that needs a newer version of libcurl. You've built curl from source in your home directory, and now you need to set the
First, create a script
Next, make that script executable:
Finally, add the following to the very top of
Once all of that is done, requests for your app will be handled by
This answer is marked "community wiki".