LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-13-2007, 11:41 AM   #1
LSOsheriff
LQ Newbie
 
Registered: Jun 2005
Location: Lincoln NE
Distribution: Kubuntu
Posts: 10

Rep: Reputation: 0
Problem copying files, perhaps due to permissions


I've been struggling with what I assume is a lack of understanding of user and group permissions.

Here's the problem. As root, I can -- of course

Code:
cp /home/garyjuilfs/lsopix/photo1.JPG /var/www/html/lsopix/
but from my PHP script, I get "... failed to open stream: Permission denied..." errors.

So I'm betting that it's a permissions problem. Which I don't understand how to zero in on. It may help to show you the output of ls -la on the "source" folder:

Code:
-rwxrwxrwx   1 apache apache      433566 Jan 23 08:18 9IMG_1152.JPG*
-rwxrwxrwx   1 apache apache      487579 Jan  2 09:44 9IMG_3830.JPG*
-rwxrwxrwx   1 apache root        134056 Jan 24 08:52 IMG_1134.JPG*
-rwxrwxrwx   1 apache root        168919 Jan 24 08:52 IMG_1135.JPG*
-rwxrwxrwx   1 apache root        165419 Jan 24 08:52 IMG_1136.JPG*
-rwxrwxrwx   1 apache root           136 Jan 17 11:40 test*
[root@lsosheriff lsopix]#
I'm also betting that the PHP "user" is "apache" and that the difference between root and apache permissions is what's maybe causing this.

If so, what's the cure? Can I perhaps have PHP run the script as "root"? I would have no difficulty (even security-stupidity-wise) changing all the files in the folder so that ANY user could read them. Whatever works.

Ideas?

Thank you.
 
Old 02-13-2007, 12:00 PM   #2
wpn146
Member
 
Registered: Jan 2005
Distribution: Solaris, Linux Fedora Core 6
Posts: 170

Rep: Reputation: 30
The user apache runs as can be configured in the httpd.conf file. Often it runs as "nobody". It is dangerous to run as root. Probably the best compromise is to use a user that has the minimum of rights that will still get the job done. Then that user may have ownership of the directory you wish to allow apache/PHP to write to.
 
Old 02-15-2007, 03:49 PM   #3
LSOsheriff
LQ Newbie
 
Registered: Jun 2005
Location: Lincoln NE
Distribution: Kubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Problem copying files, perhaps due to permissions

Thanks very much for the response; my path of action is becoming a little clearer.

I have determined from httpd.conf that the user is "apache" and the group is "apache".

So what command or commands can now be utilized to change the ownership of all files in both dirs, so as to allow my PHP scripts to successfully copy the files?

Thanks again.
 
Old 02-15-2007, 11:40 PM   #4
wpn146
Member
 
Registered: Jan 2005
Distribution: Solaris, Linux Fedora Core 6
Posts: 170

Rep: Reputation: 30
Code:
chown -R apache:apache <path>
 
Old 02-16-2007, 08:45 AM   #5
LSOsheriff
LQ Newbie
 
Registered: Jun 2005
Location: Lincoln NE
Distribution: Kubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Problem copying files, perhaps due to permissions

Thank you for the response.

The chown has been done on both directories.

Which results in the following for the source file

Code:
-rwxrwxrwx  1 apache apache 1852073 Dec 22 09:32 161DSC02780.JPG*
Now for the PHP code:

Code:
<?php
$filename = '/var/www/html/lsopix/161DSC02780.JPG';
 
 if (file_exists($filename)) {
    echo "The file $filename exists";
 } else {
    echo "The file $filename will now be moved to live server";
    $newfile = '/home/garyjuilfs/lsopix/161DSC02780.JPG';
 
 if (!copy($newfile, $file)) {
    echo "failed to copy";
 }
 }
 ?>
Which, when run from a remote browser returns the "failed to copy" error. And, the file does not show up in the destination dir.

I wonder if we are back to your original comment about configuring user "apache". The commonhttpd.conf file (an include from httpd2.conf) shows:

Code:
User apache
Group apache
but there is no configuration verbiage. I can not seem to locate examples of the configuration on the net so I would appreciate it if someone could point me toward those.

Or even tell me if I'm headed down the wrong road.

Thanks again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying files to windows box - Could not change permissions for robertpolson Linux - Networking 3 01-28-2007 12:06 AM
Copying files as root without changing permissions BillyGalbreath Linux - General 3 12-28-2005 08:39 AM
Weird problem copying files with Samba... iammike Linux - Networking 2 04-12-2005 05:19 PM
Problem copying files to vfat floppy Malcolm Dobson Linux - Newbie 11 03-09-2005 07:10 PM
Nautilus problem copying files robbow52 Linux - Software 0 09-04-2004 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration