1

I've designated the tmp directory to be /tmp (at the Drupal admin path admin/config/media/file-system). This setting is confirmed by running dpm(file_directory_temp()); from devel/php.

The permissions of /tmp/drupal_debug.txt (including SELinux settings, which I learned about here) are like so:

$ ls -ltZ /tmp/
-rwxrwxrwx. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 drupal_debug.txt

Further, if I run dd("Foo") from within the PHP CLI tool phpsh using the drush integration to get a bootstrapped Drupal environment, then I'm able to use dd() to print to this file without issue. Is there something additional I need to do to allow Apache to write to this file?

There are no errors in the Apache log, and notably, the issue persists even when I run sudo setenforce 0.

Another interesting point: the PHP test snippet from this StackOverflow question returns "Success" when I run it from devel/php, in other words Drupal does feel it can write to an arbitrary file in /tmp. However, if I modify the code to the following form:

 $handle = fopen("/tmp/drupal_debug.txt", "x");
 if ($handle) echo "Success!";
 else print_r(error_get_last());

then I get this warning, and no success message:

Warning: fopen(/tmp/drupal_debug.txt): failed to open stream: File exists in eval() (line 1 of /srv/www/decipher-storyscope/public_html/decipher/7f/profiles/storyscope/modules/contrib/devel/devel.module(1285) : eval()'d code).

This is true even if I delete the /tmp/drupal_debug.txt file.

However, as discussed in the comments, no file is created when running this snippet over the web, whereas, an empty file is created if I run the same snippet from the PHP command line.

NB. The function works fine when the code is installed and dd() called on Ubuntu.

0

1 Answer 1

1

I got advice from my sysadmin: put the tmp directory in /srv/www.

shell> sudo mkdir /srv/www/my-project/tmp
shell> sudo chmod a+w /srv/www/my-project/tmp

and in Drupal's settings.php:

$conf['file_temporary_path'] = '/srv/www/my-project/tmp';

Then: tail -f /srv/www/my-project/tmp/drupal_debug.txt works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .