Hello
Got a tricky one which I’ve been puzzled over all day so far so I hope someone here can help me out a little.
Using a webserver and PHP script, to copy files from PATH_1 to PATH_2. For some reason, when I use “cp” or “rsync”, it will copy files OK and folders, but NOT the CONTENTS of folders!!
Example … within the “Documents” folder, there are two files and a sub-folder:
file1.xls
file2.xls
myFolder
within “myFolder” there are three files
doc1.doc
doc2.doc
doc3.doc
If I use my PHP script, the files in the base folder (file1.xls and file2.xls), and the sub-folder (myFolder) is copied OK but the CONTENTS of the sub-folder (on the target) is empty.
HOWEVER, if I use the same RSYNC or CP command through terminal, the files, sub-folder and the contents of the sub-folder are copied OK.
Permissions on the source file are for anyone in the user group (of which I have added wwwrun) and rsync should preserve file permissions.
It’s got to be permissions. For a brief test, take the server off line (don’t expose it to the Internet!) and temporarily change the permissions on all files in the named folders to world-writeable (chmod 777). Log in locally with a Web browser on that machine, or on one other trusted machine on a small network. I’ll bet it works then.
Of course, you can’t leave it like that, you’ll have to tinker with the permissions and ownerships. As a general rule, the reason why the webserver has extremely limited write permission is for security. You’re deliberately circumventing that, so be very, very careful.
Someone else here with more knowledge of PHP might pipe in with specific recommendations (I know how to write scripts and make it work, but I’ve never done what you’re doing), and you could also check out the RIBS package, which is an already-written PHP script that does just what you’re talking about. Do a Google on “+PHP +RIBS” and it should be the first hit.
Thanks for the reply; I don’t think it’s permissions, after all, it creates the sub-folder but then refuses to write any of the files contained within.
A quick ls -l after the task shows correct permissions on the new folder
Looking at RIBS, it’s run via CRON and so not a run-time solution, which is what I’m trying to do here.
By the way, I used the following rsync command via php “exec”:-
Could you post a recursive listing of the directory structure on the
source side?
ls -lR /path/to/source/Documents
Doing so may yield something valuable. Also have you restarted Apache
since you made wwwrun a member of the required group?
Finally when you ran rsync manually did you do so as the wwwrun user?
Good luck.
badger fruit wrote:
> Thanks for the reply; I don’t think it’s permissions, after all, it
> creates the sub-folder but then refuses to write any of the files
> contained within.
>
> A quick ls -l after the task shows correct permissions on the new
> folder
>
> Looking at RIBS, it’s run via CRON and so not a run-time solution,
> which is what I’m trying to do here.
>
> By the way, I used the following rsync command via php “exec”:-
>
>
> Code:
> --------------------
>
> $cpCommand = “rsync --verbose --progress --stats --compress --recursive --times --perms --links “$sourceName” “$destinationFolder””;
> exec($cpCommand, $cpOutput);
>
> --------------------
>
>
> $cpOutput reads:-
>
>
> Code:
> --------------------
>
> Array ( [0] => sending incremental file list [1] => myFolder/ [2] => [3] => Number of files: 11 [4] => Number of files transferred: 0 [5] => Total file size: 105149611 bytes [6] => Total transferred file size: 0 bytes [7] => Literal data: 0 bytes [8] => Matched data: 0 bytes [9] => File list size: 367 [10] => File list generation time: 0.001 seconds [11] => File list transfer time: 0.000 seconds [12] => Total bytes sent: 384 [13] => Total bytes received: 16 [14] => [15] => sent 384 bytes received 16 bytes 800.00 bytes/sec [16] => total size is 105149611 speedup is 262874.03
>
> --------------------
>
>
> So it would seem that the rsync recognises there are 11 files in the
> folder and also realises that it’s transferred 0 of them!
>
> Help!!!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
bgrsvr-y:/ # ls -lR /home/foo/mymusic/1200\ Mics\ -\ The\ Time\ Machine/
/home/myuser/lan/music/1200 Mics - The Time Machine/:
total 102860
-rwxr--r-- 1 myuser users 13494495 Jan 8 2009 1200 Mics - 1001 Arabian Nights.mp3
-rwxr--r-- 1 myuser users 11319519 Jan 8 2009 1200 Mics - Egypt (Land Of The Pharaohs).mp3
-rwxr--r-- 1 myuser users 13600392 Jan 8 2009 1200 Mics - Garden Of Eden.mp3
-rwxr--r-- 1 myuser users 9786690 Jan 8 2009 1200 Mics - Glories Of Greece.mp3
-rwxr--r-- 1 myuser users 12284433 Jan 8 2009 1200 Mics - Rock Into The Future.mp3
-rwxr--r-- 1 myuser users 10404965 Jan 8 2009 1200 Mics - Shiva's India.mp3
-rwxr--r-- 1 myuser users 12864513 Jan 8 2009 1200 Mics - Stoned Henge.mp3
-rwxr--r-- 1 myuser users 10825176 Jan 8 2009 1200 Mics - The Creation.mp3
-rwxr--r-- 1 myuser users 10538340 Jan 8 2009 1200 Mics - The Mayans, Incas & Aztecs.mp3
-rw-r--r-- 1 myuser users 31088 Dec 16 2008 209.jpg
bgrsvr-y:/ #
No, I have done this now though - well spotted, it never crossed my mind to do this as I figured each EXEC would spawn a new wwwrun user to do the commands … ok done this and re-tried, still not doing the contents of sub-dirs … just out of interest, I instructed the machine to grab one of the files from within the sub-directory and that copied over OK :\
No, login as wwwrun asks for a password which I don’t know … I don’t wish to go changing it using passwd in case it has any adverse effects on the webserver.
So it’s probably not permissions, but testing w/wwwrun would be nice (so
would adding ‘a’ to the list of ls flags which I should have remembered
before… sorry). wwwrun probably doesn’t have a password, but you can
become that user if you have root privileges and start out as root (you do
it appears based on your prompt):
su - wwwrun
Good luck.
badger fruit wrote:
> ab@novell.com;2095820 Wrote:
>> Could you post a recursive listing of the directory structure on the
>> source side?
>>
>> ls -lR /path/to/source/Documents
>>
>
>
>
> Code:
> --------------------
>
> bgrsvr-y:/ # ls -lR /home/badger_fruit/lan/music/1200\ Mics\ -\ The\ Time\ Machine/
> /home/badger_fruit/lan/music/1200 Mics - The Time Machine/:
> total 102860
> -rwxr–r-- 1 badger_fruit users 13494495 Jan 8 2009 1200 Mics - 1001 Arabian Nights.mp3
> -rwxr–r-- 1 badger_fruit users 11319519 Jan 8 2009 1200 Mics - Egypt (Land Of The Pharaohs).mp3
> -rwxr–r-- 1 badger_fruit users 13600392 Jan 8 2009 1200 Mics - Garden Of Eden.mp3
> -rwxr–r-- 1 badger_fruit users 9786690 Jan 8 2009 1200 Mics - Glories Of Greece.mp3
> -rwxr–r-- 1 badger_fruit users 12284433 Jan 8 2009 1200 Mics - Rock Into The Future.mp3
> -rwxr–r-- 1 badger_fruit users 10404965 Jan 8 2009 1200 Mics - Shiva’s India.mp3
> -rwxr–r-- 1 badger_fruit users 12864513 Jan 8 2009 1200 Mics - Stoned Henge.mp3
> -rwxr–r-- 1 badger_fruit users 10825176 Jan 8 2009 1200 Mics - The Creation.mp3
> -rwxr–r-- 1 badger_fruit users 10538340 Jan 8 2009 1200 Mics - The Mayans, Incas & Aztecs.mp3
> -rw-r–r-- 1 badger_fruit users 31088 Dec 16 2008 209.jpg
> bgrsvr-y:/ #
>
>
> --------------------
>
>
>
> ab@novell.com;2095820 Wrote:
>> Also have you restarted Apache
>> since you made wwwrun a member of the required group?
>>
>
> No, I have done this now though - well spotted, it never crossed my
> mind to do this as I figured each EXEC would spawn a new wwwrun user to
> do the commands … ok done this and re-tried, still not doing the
> contents of sub-dirs … just out of interest, I instructed the machine
> to grab one of the files from within the sub-directory and that copied
> over OK :
>
> ab@novell.com;2095820 Wrote:
>> Finally when you ran rsync manually did you do so as the wwwrun user?
>>
>
> No, login as wwwrun asks for a password which I don’t know … I don’t
> wish to go changing it using passwd in case it has any adverse effects
> on the webserver.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
The reason was so we could see the permissions on the directory itself.
My concern initially was that you could see the directory because of the
parent directory’s permissions but could not see or go into the directory
itself because of a missing read or execute bit, respectively. As you
have, since then, mentioned you could copy a single file out of that child
directory using the method that is not working otherwise I doubt
permissions are involved at all.
So you had ‘operation not permitted’ when doing the rsync as the wwwrun
user running from the shell? That seems odd since you were able to do one
file from within there before.
Good luck.
badger fruit wrote:
> Hmm, I edited /etc/passwd to allow wwwrun log in and su’d to it; I get
> told “operation not permitted”
>
> I’m sorry, I don’t get what you mean, adding an “a” to list of what
> flags?
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Yeah, odd isn’t it!!
it’s almost like wwwrun doesn’t have permission to write to the destination folder but an ls -l says that it’s owned by the main system user (username is badgerfruit), and the “users” group - of which wwwrun is part of!
For now, it’s a pain in the backside more than anything, I’ll re-code my PHP so if(is_dir($source)) { do nothing } else { do something } … will look at this again tomorrow … I’ve been staring at three shells, one webpage and two PHP files all day and now my eyes are going funny!!
On a side note, the user badgerfruit can perform the rsync flawlessly, does anyone know how I can su to it (the account has a password) using PHP?
I tried the obvious: $myCommand = “su badgerfruit -c “rsync …””; but when exec’d, it doesn’t work (as from konsole, the “su badgerfruit” prompts for a password)
I’ve even tried
$myCommand = “su badgerfruit -c “rsync …”; mypassword”; but that doesn’t work either
Setup sudo via the /etc/sudoers file to let wwwrun execute that as
badgerfruit with the NOPASSWD parameter (for lack of the correct term) and
then use sudo instead of su.
Good luck.
badger fruit wrote:
> Yeah, odd isn’t it!!
> it’s almost like wwwrun doesn’t have permission to write to the
> destination folder but an ls -l says that it’s owned by the main system
> user (username is badgerfruit), and the “users” group - of which wwwrun
> is part of!
>
> For now, it’s a pain in the backside more than anything, I’ll re-code
> my PHP so if(is_dir($source)) { do nothing } else { do something } …
> will look at this again tomorrow … I’ve been staring at three shells,
> one webpage and two PHP files all day and now my eyes are going funny!!
>
> On a side note, the user badgerfruit can perform the rsync flawlessly,
> does anyone know how I can su to it (the account has a password) using
> PHP?
>
> I tried the obvious: $myCommand = “su badgerfruit -c “rsync …””;
> but when exec’d, it doesn’t work (as from konsole, the “su badgerfruit”
> prompts for a password)
>
> I’ve even tried
>
> $myCommand = “su badgerfruit -c “rsync …”; mypassword”; but that
> doesn’t work either
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/