LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2010, 10:35 AM   #1
tonytc
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
need help with apache and file ownership!


Hi,

I'm new to linux admin. and have been thrown in the deepend at work. I have just set up CentOS 5.4 on a VPS to act as a webserver. I have added apache as the webserver and vsftp for ftping the files onto the server and set up virtual hosts so far so good.

However, when I upload files through the site I run into a problem, the files are owned by the 'apache' user. The website scripts are owned by 'user' (the account that ftp'd the files onto the server).

I assume that I cannot manipulate the uploaded files because the owner of the scripts and the owner of the files is different.

Can someone advise me what is the best way to address this problem.

Many thanks,

Tony
 
Old 04-19-2010, 12:22 PM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Can you keep user and apache in the same group and after uploading change the permission to be writable by group.
 
Old 04-19-2010, 07:48 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
If you are uploading direct to the Apache document and cgi dirs, then you can

chmod g+s dirname

which will force any files put in there to be owned by the group owner of the dir (ie apache/httpd/ whatever).
 
Old 04-20-2010, 04:14 AM   #4
tonytc
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for replying guys,

I'm still confused though - The files are being uploaded by a file upload form in the website. Am I correct in thinking that I cannot delete /alter the files on the server using php if the php script owner is different from the uploaded files owner?

If so what settings can I use to make sure that the files are set to the same owner as the website scripts or do I have to put apache and user in the same group?

Also, is there a way to set default permissions that are automatically applied to any files that are uploaded to a particular directory?

Thanks very much.

Tony
 
Old 04-20-2010, 08:32 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Have you read my previous? Google it up for more info if you want (SGID / set group id.)
 
Old 04-21-2010, 04:24 AM   #6
tonytc
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Hi Chris,

Thanks for your reply, I have no idea what you mean when you say 'uploading to the apache document and CGI dirs'

I need to know more about how services are run on the OS with relation to the user and group policy etc. Specifically, the owner of the php scripts is 'user' and 'user' belongs to the group 'user'. Apache runs as user 'apache' and is part of the group 'apache'.

I used usermod to add the 'apache' user to the group 'user'. I also used chmod so that all files uploaded to the upload directory are in the group 'user'. (not figured out how to automatically set the rwx permissions on uploaded files yet).

What I think I need to know is, who is the user for a web request? ie. does a php script run as user 'apache' or as the user that owns the document on the OS? Obviously, a web user is not connecting to the server as 'user' so are php scripts run as 'apache' user?

Any articles about webservers, uploads and security that people are aware of would be very useful.

Many thanks
 
Old 04-21-2010, 08:51 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
If it's apache who handles PHP on your site it is indeed the user who runs
the httpd daemon that will run your scripts, and be the owner of the files.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Ownership and permissions for apache webdirs hua Linux - Server 2 07-30-2009 04:33 PM
apache FollowSymLinks not working unless ownership is same mvidberg Linux - Server 1 05-16-2008 06:46 PM
apache doc root ownership lt_wentoncha Linux - Software 3 06-30-2006 05:54 PM
Apache File Ownership wenberg Linux - Software 2 04-02-2004 10:39 PM
Apache/Samba file permissions/ownership seedsca Linux - Networking 0 03-28-2004 10:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:54 PM.

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