demienx
asked on
Runing a php script as the FTP user, or grant php user r/w privileges with inheritance
Hi there,
let me tell you what I'm trying to do, what I've tried already...
I have a php script that accesses a folder named content where some
persons will be uploading image galleries. The script does read the
html files and makes some changes.
All this works fine when run in a windows box with apache + php, as
there is no problem with the permissions.
What I do need:
. I would like apache run the php script as the FTP user. So it has the same privileges, an
if it creates a new file, the ftp user will be able to delete it without
having to make the file world writable.
. another way of doing so, would be grant the "www" user to r/w any files/folders untder
that "content" folder. This also includes newly created ones by the FTP user.
A not so ellegant sollution, would be change the FTP daemon defaul folder and file
permission, so it's wold readble & writable... But this is not my prefered sollution.
I have tried already creating a folder from a php script and do a chmod ("folder", 01755); so the owner is "www".
Also tried the chmod ("folder", 04777); and lots of variants, but seems that the setuid and stiky bits
have no real effect, as when the ftp user creates a new folder under the "content" folder, the "www" user
(the one that runs for apache) has no write rights on that folder.
Something like giving "root" privileges to the "www" user, is not my preferred sollution...
The scenario:
the server is a FreeBSD 4.9 with Apache/1.3.29 and PHP 4.3.4
I hope everything about what I do ask is quite clear here, if there's something uncler, I will be more than willing to clarify.
Thanks a lot in advance!
Demien.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
umask may be the solution to your problem if it's on your distribution...
man umask
The umask is used by open(2) to set initial file permis
sions on a newly-created file. Specifically, permissions
in the umask are turned off from the mode argument to
open(2) (so, for example, the common umask default value
of 022 results in new files being created with permissions
0666 & ~022 = 0644 = rw-r--r-- in the usual case where the
mode is specified as 0666).
Mike
man umask
The umask is used by open(2) to set initial file permis
sions on a newly-created file. Specifically, permissions
in the umask are turned off from the mode argument to
open(2) (so, for example, the common umask default value
of 022 results in new files being created with permissions
0666 & ~022 = 0644 = rw-r--r-- in the usual case where the
mode is specified as 0666).
Mike
ASKER
frugle,
sorry but I don't know how this will make the FTP uploaded files to be have the permission I do want... I have tried by loggin into my server thru SSH, then using umask, but seems to have no effect in the FTP upload, as permissions are not affected on creation of new files when I do change umask thru SSH login...
Please tell me if I'm doing wrong. Thanks!
You may want to post a pointer to this question in one of the *nix groups, someone there may have a better idea of how umask/numask works. It could be user specific, which would require putting something in the equivalent of bash.rc for the FTP user.
Can't help you much more myself - I'm not a *nix guru - just another perl hacker :P
Mike
Can't help you much more myself - I'm not a *nix guru - just another perl hacker :P
Mike
ASKER
Well, after lots of searching all over the net and e.e. network, I dound that the sollution for this would be a headache, whenever feasible. Basically I would need to install apache server with suEXEC support and apache as a CGI install. As this would be a performance downgrade and somewhat complex for me to setup, I have found two other works arrounds.
Here is a link to a thread about suEXEC:
https://www.experts-exchange.com/questions/20811864/files-folders-users-access-rights-problems.html?query=SuExec&topics=103
- There was one that I found someone used here in e.e., and basically consist into making the script access the html pages by making a FTP connection with the FTP-user data, so that way permissions remain to that user. The downside of this method is the speed... it all depends on your needs.
Here is the link: https://www.experts-exchange.com/questions/20836213/creating-dirs-subdirs-safe-mode-and-other-trouble.html
- The other sollution is the one I'll be using, and basically consist into running my php script as cmdline call from a cron job that my FTP-user creates. So permission that way are the FTP-user ones. This suits ok for my scrip functions, as does not need human intervention.
About the resollution, the initial problem was not solved, as I got not the way to run my script as the FTP user, but the
help on. There where two aproaches with group permissions, and a gold piece of software that will solve a problem I had with my current FTP server. So, split points for you guys, and thanks for your hep!
Demien.
ASKER
sorry for the late reply, I've been out...
frugle,
having them in the same group, would be better than chmod 777, but stills has the main problem I do have, setting the permission of files and folders. I do not want the users to chmod manually when they do upload a new file (644 by default) or create a new folder (755 by default) to make the file writeable to the group. Does not solve the issue, but thanks a lot for your help.
Squinky,
the group sollution problem still the same as above, but he pureftpd server looks very very interesting and will hopefully allow me to solve another problem I had with my current FTP server. I'll rewqard you for a so interesting piece of software ;)
I'll try to use the FTP server, but still would like to be able tu run a php script as another user. I think that with CGIs it was possible to setuid it, but for php scripts there is a need of some wrapper... I'm still looking arround for this.