Rather than hard-wiring some paths in my php.ini configuration, I'd like to configure them using system variables that are shared in some other places such as my Apache configuration. I've done some searching and couldn't find the right mix of keywords to discover if there's a way to do this.
Does anyone know if this can be done?
upload_tmp_dir = $SCRATCH_HOME/uploads
Now SCRATCH_HOME can be exported in the environment as /tmp or /var/scratch or whatever I want it to be.
According to the PHP docs, environment-variables can indeed be used in the configuration file.
It doesn’t say anything about what syntax to use, but it is the same as with Apache’s configuration file which uses *nix syntax. So for example, if you want PHP to use the system temp-directory, you would use this:
You can confirm that it is active with the following script:
This feature is not well documented. Before I begin, I just want to specify my configurations: I'm using Windows 7-64bit, PHP 5.4.3, Apache HTTP Server 2.2.x, I've set my environmental variable
PHP_HOME=C:\tools\php-5.4.3
(PHP installation directory). I use the variable in myhttpd.conf
andphp.ini
fileNote: I will be omitting some text for brevity.
In the
httpd.conf
fileIn the
php.ini
fileYou can use it, and it is well documented now:
https://www.php.net/manual/en/configuration.file.php#example-36
Try configuring PHP via Apache config files:
Works fine for me. (psst, you cannot change
upload_tmp_dir
using .htaccess)