Setting TMPDIR for Apache

Hello!

We are running Apache with mod_php, installed from ports.

Some PHP applications are trying to write temporary files into a directory which should be specified by TMPDIR environment variable. When TMPDIR is not set, they fall back to /tmp or /var/tmp which in our case is outside PHP's open_basedir.

I would like to make them write to directory /var/tmp/php, but I can't figure out a clean way to specify TMPDIR for the case when Apache is started from the rc.d script. In the past I have written the TMPDIR setting directly into the /usr/local/etc/rc.d/apache22 script (which I don't particularly like), but now this script has become so complex I'm no longer sure how to even do this.

Any suggestions?
 
vatson said:
Some PHP applications are trying to write temporary files into a directory which should be specified by TMPDIR environment variable. When TMPDIR is not set, they fall back to /tmp or /var/tmp which in our case is outside PHP's open_basedir.

I'm using open_basedir with these options in php.ini (also you can set them whithin .htaccess):

Code:
open_basedir = /store/www/php:/usr/local/share/pear
;....
upload_tmp_dir = /store/www/php/tmp
;....
session.save_path = "/store/www/php/tmp"

P.S. Never heard about TMPDIR xD
 
gordon@ said:

This doesn't seem to have an effect. I added the following line:
Code:
SetEnv TMPDIR /var/tmp/php

I tried adding it first to the main httpd.conf file outside any conditional blocks, and then in one particular virtual host in extra/httpd-vhosts.conf. Then I ran a simple php script in browser, which contains just:

Code:
<?php echo sys_get_temp_dir(); ?>

In both cases the output was /var/tmp

Then I just modified the /usr/local/etc/rc.d/apache22 script and added this line near the beginning:

Code:
TMPDIR=/var/tmp/php;export TMPDIR

This seems to have done the trick, my test script now outputs /var/tmp/php
 
Back
Top