"problem writing temporary file," again

Getting this error:

problem writing temporary file '/var/www/httpdocs/piwik/tmp/templates_c/wrt4bb65e11912f2'

Backtrace:
#0 /var/www/httpdocs/piwik/libs/Smarty/internals/core.write_file.php(32): Piwik_Smarty->trigger_error('problem writing...')
#1 /var/www/httpdocs/piwik/libs/Smarty/internals/core.write_compiled_resource.php(29): smarty_core_write_file(Array, Object(Piwik_Smarty))
#2 /var/www/httpdocs/piwik/libs/Smarty/Smarty.class.php(1431): smarty_core_write_compiled_resource(Array, Object(Piwik_Smarty))
#3 /var/www/httpdocs/piwik/libs/Smarty/Smarty.class.php(1261): Smarty->_compile_resource('Installation/te...', '/var/www/vhosts...')
#4 /var/www/httpdocs/piwik/core/View.php(146): Smarty->fetch('Installation/te...')
#5 /var/www/httpdocs/piwik/plugins/Installation/View.php(52): Piwik_View->render()
#6 /var/www/httpdocs/piwik/plugins/Installation/Controller.php(85): Piwik_Installation_View->render()
#7 /var/www/httpdocs/piwik/plugins/Installation/Installation.php(73): Piwik_Installation_Controller->welcome('The configurati...')
#8 [internal function]: Piwik_Installation->dispatch(Object(Piwik_Event_Notification))
#9 /var/www/httpdocs/piwik/libs/Event/Dispatcher.php(213): call_user_func_array(Array, Array)
#10 /var/www/httpdocs/piwik/core/PluginsManager.php(362): Event_Dispatcher->addObserver(Array, 'FrontController...')
#11 /var/www/httpdocs/piwik/core/PluginsManager.php(248): Piwik_PluginsManager->addPluginObservers(Object(Piwik_Installation))
#12 /var/www/httpdocs/piwik/core/PluginsManager.php(165): Piwik_PluginsManager->loadPlugins()
#13 /var/www/httpdocs/piwik/core/FrontController.php(209): Piwik_PluginsManager->setPluginsToLoad(Array)
#14 /var/www/httpdocs/piwik/index.php(103): Piwik_FrontController->init()
#15 {main}

I’m sure that the permissions are set right:

chmod -R 777 tmp/

was set, so it should work just fine.

Any ideas? I’ll be happy to post phpinfo() if it helps.

Cheers guys,

Just to add to this, when I go into the templates_c folder, it creates a bunch of temp files such as wrt7Jk5kh, which are chmod 500 by apache:apache.

So how do I get it to write out these temp files as 777?

Cheers guys,

Smarty creates a temporary file and then opens it to write to it.

Can you put this into a .php file and test it from your browser?

<?php
$f = tempnam('/tmp', 'test');
var_dump(fileperms($f));
var_dump(stat($f));

var_dump(fileperms(__FILE__));
var_dump(stat(__FILE__));

[quote=vipsoft @ Apr 4 2010, 08:01 PM]Smarty creates a temporary file and then opens it to write to it.

Can you put this into a .php file and test it from your browser?

<?php
$f = tempnam('/tmp', 'test');
var_dump(fileperms($f));
var_dump(stat($f));

var_dump(fileperms(__FILE__));
var_dump(stat(__FILE__));

[/quote]

Here you are.

int(33152)
array(26) {
  [0]=>
  int(64768)
  [1]=>
  int(21069828)
  [2]=>
  int(33152)
  [3]=>
  int(1)
  [4]=>
  int(48)
  [5]=>
  int(48)
  [6]=>
  int(-1)
  [7]=>
  int(0)
  [8]=>
  int(1270548583)
  [9]=>
  int(1270548583)
  [10]=>
  int(1270548583)
  [11]=>
  int(-1)
  [12]=>
  int(-1)
  ["dev"]=>
  int(64768)
  ["ino"]=>
  int(21069828)
  ["mode"]=>
  int(33152)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(48)
  ["gid"]=>
  int(48)
  ["rdev"]=>
  int(-1)
  ["size"]=>
  int(0)
  ["atime"]=>
  int(1270548583)
  ["mtime"]=>
  int(1270548583)
  ["ctime"]=>
  int(1270548583)
  ["blksize"]=>
  int(-1)
  ["blocks"]=>
  int(-1)
}
int(33188)
array(26) {
  [0]=>
  int(64768)
  [1]=>
  int(22712556)
  [2]=>
  int(33188)
  [3]=>
  int(1)
  [4]=>
  int(0)
  [5]=>
  int(0)
  [6]=>
  int(-1)
  [7]=>
  int(138)
  [8]=>
  int(1270548583)
  [9]=>
  int(1270547782)
  [10]=>
  int(1270547782)
  [11]=>
  int(-1)
  [12]=>
  int(-1)
  ["dev"]=>
  int(64768)
  ["ino"]=>
  int(22712556)
  ["mode"]=>
  int(33188)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(0)
  ["gid"]=>
  int(0)
  ["rdev"]=>
  int(-1)
  ["size"]=>
  int(138)
  ["atime"]=>
  int(1270548583)
  ["mtime"]=>
  int(1270547782)
  ["ctime"]=>
  int(1270547782)
  ["blksize"]=>
  int(-1)
  ["blocks"]=>
  int(-1)
}

But the file is chmod 500 to apache:apache, which is not the user for that vhost, and anyway a stupid chmod to give to a temp file.

Any way to change this behaviour so it writes as 777?

Thanks for the quick response. Sorry for my slow one.

//deleted//

Ok. Don’t believe the user comments on the PHP manual page. tempnam() does respect the umask.

Try editing your apache startup script to use a less restrictive umask (e.g., 0022).

[quote=vipsoft @ Apr 6 2010, 10:34 PM]Ok. Don’t believe the user comments on the PHP manual page. tempnam() does respect the umask.

Try editing your apache startup script to use a less restrictive umask (e.g., 0022).[/quote]

I’ve tried everything. I added “umask 002” to httpd.conf (which failed, but works on some distros apparently), to /etc/syscontrol/httpd, which did nothing, and to the initscript /etc/init.d/httpd.

Then I obviously restarted the httpd service.

The files still get created with chmod 500, (and owned by apache:apache as before.)

Do you have any other ideas, or any reasons for why the above did nothing?

Thanks for your help so far, it’s much appreciated.

Edit: For what it’s worth, I’m running Red Hat:

cat /proc/version

Linux version 2.6.18-164.11.1.el5PAE (mockbuild@hs20-bc1-2.build.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Wed Jan 6 13:43:57 EST 2010

Try patching the following files:

piwik/libs/Smarty/internals/core.write_file.php:

Index: core.write_file.php
===================================================================
--- core.write_file.php    (revision 2059)
+++ core.write_file.php    (working copy)
@@ -25,7 +25,7 @@
 
     // write to tmp file, then rename it to avoid file locking race condition
     $_tmp_file = tempnam($_dirname, 'wrt');
-
+    chmod($_tmp_file, 0600);
     if (!($fd = @fopen($_tmp_file, 'wb'))) {
         $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
         if (!($fd = @fopen($_tmp_file, 'wb'))) {

piwik/core/CacheFile.php:

Index: CacheFile.php
===================================================================
--- CacheFile.php    (revision 2059)
+++ CacheFile.php    (working copy)
@@ -78,6 +78,7 @@
         // Write cache to a temp file, then rename it, overwritng the old cache
         // On *nix systems this should guarantee atomicity
         $tmp_filename = tempnam($this->cachePath, 'tmp_');
+        chmod($tmp_filename, 0600);
         if ($fp = @fopen($tmp_filename, 'wb')) {
             @fwrite ($fp, $cache_literal, strlen($cache_literal));
             @fclose ($fp);

Hi again,

Thanks for your reply. The patches give me the somewhat more useful error message:

chmod() [function.chmod]: SAFE MODE Restriction in effect.  The script whose uid is 10003 is not allowed to access /var/www/piwik/tmp/templates_c/wrta6QQDZ owned by uid 48 
in '/var/www/piwik/libs/Smarty/internals/core.write_file.php' at the line 28

However, my .htaccess in the root of the domain and the piwik directory both say:

php_value safe_mode "0"
php_flag safe_mode off

and phpinfo() gives me that safe mode globally is off, but local value is on. What gives?

Look for local php.ini files along the directory path between the webroot and the piwik folder.

The server we run uses plesk. Plesk had a check box for safe mode on. How irritating. That fixed it.

Thanks so much for your help, I have piwik running now.

The only thing now is that even though it’s running and it’s collecting info in the database (I’m looking at the DB itself), the actual interface shows no visits or anything. Any ideas?

Make sure you’re viewing ‘today’ in the calendar, and that your php timezone is configured correctly – you would have seen an Installation warning for the latter.

I did indeed get a warning. Checking “today” in calendar does not work for dashboard or anything, though I do see data in Visitors → Visitor Log.

I suppose I’ll wait a day to see if it all shows up then. I couldn’t find a way to go back and see how to fix the timezone warnings.

Another problem was the UTF8 warnings it shows when setting up. Is it worth fixing this?

Best,

The timezone mismatch causes reports to lag. This is in the FAQ. This has to correspond to the timezone of the MySQL server.

We’re making timezone configureable in the next release (0.6). In the meantime, you can set it manually in your piwik/index.php. See http://php.net/timezones for a list of supported timezone strings. (Varies depending on your PHP version, timezonedb package, and whether or not your PHP build was patched to use tzdata.)

-    @date_default_timezone_set(date_default_timezone_get());
+    @date_default_timezone_set('America/New_York');

If you’re not going to query your Piwik database outside of Piwik, then you can leave it.

[quote=vipsoft @ Apr 8 2010, 07:11 PM]The timezone mismatch causes reports to lag. This is in the FAQ. This has to correspond to the timezone of the MySQL server.

We’re making timezone configureable in the next release (0.6). In the meantime, you can set it manually in your piwik/index.php. See php.net/timezones for a list of supported timezone strings. (Varies depending on your PHP version, timezonedb package, and whether or not your PHP build was patched to use tzdata.)

-    @date_default_timezone_set(date_default_timezone_get());
+    @date_default_timezone_set('America/New_York');

If you’re not going to query your Piwik database outside of Piwik, then you can leave it.[/quote]

Thanks. You’ve really been a fantastic help. Cheers!

All the best,

For this error “problem writing temporary file” SEE TICKET Error “unable to start session” instead of a proper error message · Issue #2717 · matomo-org/matomo · GitHub