2

I have the following script: /var/www/vhosts/default/download/index.php

I am using readfile(); to serve files:

$path = '/data/'. $arr["$product"] .'';
readfile($path);

But The following error is generated:

[error] [client xx] PHP Warning: readfile(/data/xxx.iso): failed to open stream: Permission denied in /var/www/vhosts/default/download/index.php on line 33, referer: http://zxc.com/

I thought it is caused by permissions, therefor I gave 777 to the /data directory and 777 to the files in /data, but didn't solve the problem. Then I changed the owner of the directory + files to apache, but also didn't solve it.

What else could be the problem? Also tried to solve it with open_basedir. but no success.

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76
Sinan
  • 83
  • 3
  • 9
  • Remove the first slash `/`for a relative path? Or is data really a top level directory? – Tim Sep 03 '14 at 13:43
  • Oh sorry, the direct folder is: /data/ (it is on a different partition) – Sinan Sep 03 '14 at 13:44
  • Does the file actually exist? (Check with [file_exists](http://php.net/manual/de/function.file-exists.php)) – Hirnhamster Sep 03 '14 at 13:44
  • Yes, the file does exist. I copied the filename from the error log and checked via SSH. The file does exist. – Sinan Sep 03 '14 at 13:45
  • Is the file in /var/www/vhosts/default/download/data/yourfile ?? – AlexDeb Sep 03 '14 at 13:50
  • Possible duplicate of [PHP - Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Sep 11 '16 at 09:38

1 Answers1

2

I found the problem. It seems SELinux was enabled. Disabled SELinux and it is working now.

Sinan
  • 83
  • 3
  • 9
  • https://stopdisablingselinux.com/ If the issue is with SELinux you should fix the related permissions issue. – Eric Rich Feb 07 '17 at 18:13