PHP copy failed to open stream: Permission denied
I have a basic LAMP server that works as I expected it to...
I tried doing something and I am having permission errors.
When I attempt to copy a file from:
$file = "/media/
to here:
$newfile = "/var/www/
using the copy function:
if (!copy($file, $newfile)) {
echo "Failed to copy $file...<br />";
}
I get this error:
Warning: copy(/media/
(line 58 is the copy function I posted above)
I have been scouring the internet and most solutions are very similar and they have not worked for me.
I have temporarily made directory /var/www/
I tested that on the source directory as well.
I looked at owner of index.php and saw root was owner even though www-data is the server user
$user = posix_getpwuid(
var_
Is
array(7) { ["name"]=> string(8) "www-data" ["passwd"]=> string(1) "x" ["uid"]=> int(33) ["gid"]=> int(33) ["gecos"]=> string(8) "www-data" ["dir"]=> string(8) "/var/www" ["shell"]=> string(17) "/usr/sbin/nologin" }
so I tested chown www-data:www-data index.php
I created an executable file
/var/www/
which contains:
#!/bin/bash
cp "/media/
and in the index.php I use:
$k = '/var/www/
$command = 'nohup '.$k.' > /dev/null 2>&1 & echo $!';
$pid = (int)$op[0];
$command = 'ps -p '.$pid;
if (isset($op[1]))echo 'It worked...'.$pid;
and it says it worked and shows a pid that looks reasonable (I never see it appear as I am watching task manager.)
The temp file does not get made.
I can run launcher from a terminal as myself and it creates the file with me as user:group
so somehow www-data can't do it
or php can't do it or what?
I checked my phpinfo and safemode and basedir and sestatus...
I haven't pulled my hair out yet, but I would if I thought it were relevant...
Question information
- Language:
- English Edit question
- Status:
- Expired
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: