move_uploaded_file: failed to open stream: Permission denied

Support for webhosts that use CentOS
Post Reply
xavxav
Posts: 1
Joined: 2011/11/10 15:06:53

move_uploaded_file: failed to open stream: Permission denied

Post by xavxav » 2011/11/10 15:28:35

Hi

I am a newbee in Linux Administration. I set up a web server with CentOS 5.6
The apache server version is 2.2.3
The php server version is 5.3.8

The site is hosted in the directory : /usr/matrix/trunk/
It is available to the "apache" user and to the "apache" group with the rights drwxr-xr-x
I have made a directory to store files in the directory /usr/matrix/tmp/
It is available to the "apache" user and to the "apache" group with the rights drwxrwxrwx
I have made an upload directory for the Apache server. The path to the directory is "/tmp/apache_upload_tmp/"
It is available to the "apache" user and to the "apache" group with the rights drwxrwxrwx

I set in the php.ini the command :
[code]file_uploads = On
upload_tmp_dir = /tmp/apache_upload_tmp
upload_max_filesize = 2M
post_max_size = 10M[/code]

I can not upload file. I get the message :
"Warning: move_uploaded_file(/usr/matrix/tmp/2011-11-10_DDD_export-2lignes.xlsx): failed to open stream: Permission denied in /usr/matrix/trunk/controllers/ImportManagement.controller.php on line 1360 Warning: move_uploaded_file(): Unable to move '/tmp/phpBpsWAz' to '/usr/matrix/tmp/2011-11-10_DDD_export-2lignes.xlsx' in /usr/matrix/trunk/controllers/ImportManagement.controller.php on line 1360"

The error occurs in the line :
[code]move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $fileTargetPath)[/code]
(where fileTargetPath is "/usr/matrix/tmp/2011-11-10_DDD_export-2lignes.xlsx")

I added some debug code in the php file to know what happends:

[code]$a=ini_get('upload_tmp_dir');
echo 'upload_tmp_dir:';
var_dump($a); echo '<br>$_FILES[\'uploadedfile\'][\'tmp_name\']:';
var_dump($_FILES['uploadedfile']['tmp_name']); echo '<br>';[/code]
I get this output :
upload_tmp_dir:string(22) "/tmp/apache_upload_tmp"
$_FILES['uploadedfile']['tmp_name']:string(14) "/tmp/phpBpsWAz"

The command upload_tmp_dir in the php.ini does not work. I think that Apache can not read or write in the directory defined in upload_tmp_dir.
I modified the command move_uploaded_file to copy the file to /tmp/ and it works.

The site works on my local computer perfectly.


In the httpd.conf file, there are the command commands :
[code]User apache
Group apache[/code]

So I suppose that Apache is ran with the "apache" user and the "apache" group. Is it right ?

I do not find any solution. Some help would be very usefull.

Regards,

Xavier

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

move_uploaded_file: failed to open stream: Permission denied

Post by pschaff » 2011/11/14 18:48:08

Welcome to the CentOS fora. Please see the recommended reading for new users linked in my signature.

Web sites, or other user content should [b]never[/b] be put in the system directory /usr/. The usual location is in /var/www/html/. The error may be due to SELinux denials, which would be quite appropriate given where you have attempted to put the web content.

CentOS 5.6 is obsolete and unsupported, and CentOS does not supply php-5.3.8. The default php is currently 5.1.6-27.el5_5.3 and the alternate php53 is at 5.3.3-1.el5_7.3. Please "yum update" to get to CentOS-5.7, describe where you got your php version and how it was installed, and [url=http://www.centos.org/modules/newbb/viewtopic.php?topic_id=28723&forum=54]provide more information about your system[/url] by running "./getinfo.sh package" and showing us the output file.

Post Reply

Return to “CentOS 5 - Webhosting Support”