1

I am trying to upload files to a Redhat server, but am getting this error:

failed to open stream: Permission denied in /var/www/html

I modified permits in all of the folders and it still doesn't work. Can anyone guide me?

My app works if I run it in a localhost, but in the server it just doesn't work.

I'm working with: Redhat v7, PHP version 5.4.16, wamp version 2.2

I've modified php.ini and httpd.conf as in another answers I read, but with no results.

Alex K
  • 8,269
  • 9
  • 39
  • 57
  • did you set 777 on the folder for test (I know it's bad to set 777 but I'm just asking) I had the same problem with Ubuntu Server and the only solution I had, was to move the file on /etc/ – everytimeicob Mar 09 '15 at 22:04
  • You need always provide absolute paths instead of relative ones. So make sure it looks like as `move_uploaded_file(__DIR__ . '/path')` but not as `move_uploaded_file('/path')` – Yang Mar 09 '15 at 23:02
  • Reworded for clarity. – Alex K Mar 09 '15 at 23:14
  • Is the error happening because it can't read the uploaded file or because it can't write to the destination? Does this issue only occur with `move_uploaded_file()` or does it occur with other operations (`touch()`,`file_get_contents()`)? Is `open_basedir` or `safe_mode` set? Is the php/apache user(and groups) the same as the file/directory owner? And could `suEXEC`/`suPHP` be affecting it (not real familiar with them, so I don't know if they could or not)? – Reed Mar 09 '15 at 23:33

2 Answers2

1

O_o wowow be quiet, no 777 !!! Others write no!! Protect your folder first with deny from all, require valid user...

Or if your folder is public, understand how do it with no 777 perms:

  • Show which user or group uses apache to run itself, in environment variables of apache config files.

  • Change owner or group of the folder you whould be upload files, and set write perms to the group or to the user.

You have various options, one of this, for example: chown myftpuser.www-data upload/ chmod g+w upload/ When you upload files apache runs over www-data group, and it have permisions to write inside folder

David
  • 1,116
  • 3
  • 18
  • 32
0

Try this before calling move_uploaded_file

chmod($path_to_file, 777);