4

I have a simple script which copies a file from one SMB mount to another. The source file system is the same, but the web server is different. I'm using PHP to process the file by copying it to a temp directory, then performing additional tasks on it. This setup was working at one point in time but it seems that it's no longer working correctly. Can someone point me in the right direction?

fstab mounts:

//192.168.0.x/share /media/folder smbfs username=user,password=mypass
//192.168.0.x/share2 /media/folder2 smbfs username=user,password=mypass

php code:

copy('/media/folder/filename.txt','/media/folder2/temp/filename.txt');

Error:

Warning: copy(/media/folder2/temp/filename.txt): failed to open stream: Permission denied in /www/myphp.php on line xx

Folder permissions (not the mount, but the source folder on the fileserver):

/media/folder = 777 
/media/folder2/temp = 777
Allan Bogh
  • 605
  • 8
  • 15
  • Is SELinux running? If so I can envision it not liking PHP talking to SMB. – Michael Berkowski Jul 10 '11 at 02:35
  • SELinux is not running, I don't think. There's no /etc/sysconfig/selinux file to cat, nor is there an sestatus program on the file server. – Allan Bogh Jul 10 '11 at 03:28
  • Just to be sure, `ls -Z /media/folder` If SELinux is there, you'll have the `-Z` option and it should list contexts. – Michael Berkowski Jul 10 '11 at 03:32
  • Thanks for the help by the way. The results list on one folder from the web server is: "? SubFoldername". Same results for the other folder with the temp directory: "? temp" – Allan Bogh Jul 10 '11 at 03:43
  • Yeah, no SELinux there. Sorry I don't have any other advice. – Michael Berkowski Jul 10 '11 at 03:55
  • If you `su` into the webserver's user acct, can you perform the `cp` manually? Would help in troubleshooting, as I don't think this is going to end up being PHP's issue... – ETWW-Dave Jul 10 '11 at 04:48
  • I can't add an answer to the question yet, but I got around the problem by using the command "copy('/media/folder/filename.txt','/tmp/filename.txt');". The files should be deleted when the system reboots or at a scheduled time based on the settings of the web server. – Allan Bogh Jul 10 '11 at 05:05

3 Answers3

1
system("cp /media/folder/filename.txt /media/folder2/temp/filename.txt");

Might work for you.

GregSchoen
  • 404
  • 3
  • 9
0

sounds like a question that is specific to permissions and the OS and not PHP .. what webserver? what is the server running as? nobody:nobody? can nobody:nobody or www-root:www-root read/write data into the directories you are trying to access?

sudo su - nobody

  • probably wont work as it will most likely have a /bin/false shell
  • nobody may not be the right account .. ps auxw | grep apache | awk {'print $1'} and see which user it is running as ... then try changing over to that account with sudo

Before PHP can have access to write the files, you need to ensure the user which the webserver is running as ... has access to read/write to the directory you are trying your copy on.

sdolgy
  • 6,963
  • 3
  • 41
  • 61
0

I changed the command to:

copy('/media/folder/filename.txt','/tmp/filename.txt');

Apparently it's more difficult to process files on an SMB share than I thought. The file should be removed when the computer's rebooted, or possibly at regular intervals, depending on the system setup.

Allan Bogh
  • 605
  • 8
  • 15