Jump to content

Topic on Project:Support desk

upload_tmp_dir - MediaWiki ignores php specified path

9
Arkasha (talkcontribs)

MediaWiki 1.17wmf1
PHP 5.2.12 (apache)
MySQL 5.0.90-log

There is a problem with a temporary folder path resolving.
Php on server side sets this directive as following:
upload_tmp_dir = /home/XXXXX/hdlwiki.com/tmp
and
open_basedir = /home/XXXXX/
However Wiki ignores these directives and tries to use /var/tmp
which is out of the allowed path.
This warning I received during Wiki installation:

     Warning: is_dir() [function.is-dir]: open_basedir restriction in effect.
File(/tmp) is not within the allowed path(s): (/home/XXXXX/) in /home/XXXXX/hdlwiki.com/www/config/Installer.php on line 474 Warning: Your session.save_path value (/tmp) appears to be invalid or is not writable.
PHP needs to be able to save data to this location for correct session operation.

As a result I cannot upload files by url. The system returns an error:

     Warning:  tempnam() [<a href='function.tempnam'>function.tempnam</a>]: open_basedir restriction in effect.
File(/var/tmp/) is not within the allowed path(s): (/home/XXXXX/)in/home/XXXXX/hdlwiki.com/www/includes/upload
/UploadFromUrl.php on line 101

What can be a solution for such problem.

Bawolff (talkcontribs)

Set the TMP (or TEMP or TMPDIR) environment variables for what you want your temp directory. (for the upload by url error)

For the install error, this can be caused if php is configured to store session files in the temp directory (sesssion.save_path in your php.ini). This should cause logins to not work at all, but perhaps only mediawiki is dissallowed, and php session handlers don't have the open_basedir restriction. If you get that warning when installing, but can still log in after the install is done, then the warning is in error, and is a bug in the installer (should probably file a bug about it).

Arkasha (talkcontribs)

Where should I set TMP variable? I have these in my LocalSettings.php

$wgEnableUploads  = true;
$wgAllowCopyUploads = true;
$wgUploadPath = "{$wgScriptPath}/images";
$wgUploadDirectory = "{$IP}/images";
$wgTmpDirectory = "{$wgUploadDirectory}/temp";

$wgGroupPermissions['sysop']['upload_by_url'] = true;

and I still have the above mentioned error. The folders for uploads are all writable. The Special:Upload shows Could not create temporary file. in red.

Bryan (talkcontribs)

putenv("TMP={$wgUploadDirectory}/temp");

UploadFromUrl appears to not support wgTmpDirectory, I believe this is a bug.

Bawolff (talkcontribs)

Really I'd consider it a bug in wfTempDir() function. Imports, and diffs (depending on config) are also affected.

Arkasha (talkcontribs)

Thank you! This solved the problem. Can it be fixed in the following MW release?

Bryan (talkcontribs)

Dunno if the fix will make it into 1.17, but in 1.18 it most likely will.

Narcisgarcia (talkcontribs)

I still see the problem in MediaWiki 1.41.1

  • If you can edit webserver site, you need to configure PHP's sys_temp_dir (this is the server's variable MediaWiki uses!)
  • If you can only edit CMS files, the only workaround is to add
$wgTmpDirectory = ini_get('upload_tmp_dir');
to LocalSettings.php
TheDJ (talkcontribs)
Reply to "upload_tmp_dir - MediaWiki ignores php specified path"