PHP copy failed to open stream: Permission denied

Asked by jamesKasper

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/user/yMedia/Movies/Family/movieName/movieName.avi";
to here:
      $newfile = "/var/www/html/home/movies/temp.avi";
using the copy function:

      if (!copy($file, $newfile)) {
        echo "Failed to copy $file...<br />";
      }

I get this error:
Warning: copy(/media/jkcbwpnet/yMedia/Movies/Family/movieName/movieName.avi): failed to open stream: Permission denied in /var/www/html/home/movies/index.php on line 58

(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/html/home/movies/ chmod 777
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(posix_geteuid());
      var_dump($user);
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/html/home/movies/launcher
which contains:
#!/bin/bash
cp "/media/jkcbwpnet/yMedia/Movies/Family/movieName/movieName.avi" /var/www/html/home/movies/temp.avi
and in the index.php I use:
        $k = '/var/www/html/home/movies/launcher';
        $command = 'nohup '.$k.' > /dev/null 2>&1 & echo $!';
        exec($command,$op);
        $pid = (int)$op[0];

        $command = 'ps -p '.$pid;
        exec($command,$op);
        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:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

What file system is the video stored on please?

Revision history for this message
jamesKasper (q-jk) said :
#2

Not sure if you are asking for the type like ext4 or location like /dev/sdc or something from /etc/fstab?
It is on a separate hard drive from the one the operating system is on, but still connected to the same machine...

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

We can find out if you run:

mount | grep -i media

What is the output please?

Revision history for this message
jamesKasper (q-jk) said :
#4

/dev/sdb1 on /media/user/xMedia type ext4 (rw,relatime,data=ordered)
/dev/sdc1 on /media/user/yMedia type ext4 (rw,relatime,data=ordered)

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

What is the output of:

ls -al /media/user/yMedia/Movies/Family/movieName/movieName.avi

Thanks

Revision history for this message
jamesKasper (q-jk) said :
#6

-rwxrwxrwx 1 user user 790681891 Mar 31 19:41 /media/user/yMedia/Movies/Family/movieName/movieName.avi

I can't remember what it had been, but I have done chmod 777 to all the media from the Movies directory on down just to test if that was a thing...
I see some newer files that have their parent directory of drwxr-xr-x and the file is only -rw-r--r-- but I haven't modified them yet. I know generally most of my directories online are 755 and files are 644 but none of what I am doing now is public. It will be all on a private intranet.

Revision history for this message
Launchpad Janitor (janitor) said :
#7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
jamesKasper (q-jk) said :
#8

No more answers? This is not answered yet...

On Apr 17, 2017 05:53, "Launchpad Janitor" <
<email address hidden>> wrote:

> Your question #601348 on Ubuntu changed:
> https://answers.launchpad.net/ubuntu/+question/601348
>
> Status: Open => Expired
>
> Launchpad Janitor expired the question:
> This question was expired because it remained in the 'Open' state
> without activity for the last 15 days.
>
> --
> If you're still having this problem, you can reopen your question either
> by replying to this email or by going to the following page and
> entering more information about your problem:
> https://answers.launchpad.net/ubuntu/+question/601348
>
> You received this question notification because you asked the question.
>

Revision history for this message
Launchpad Janitor (janitor) said :
#9

This question was expired because it remained in the 'Open' state without activity for the last 15 days.