Re: Write Permission
| From: | Richard Lynch | Date: | Wed, 06 Dec 2000 02:21:59 +0000 |
| Subject: | Re: Write Permission | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28819@lists.php.net to get a copy of this message | ||
> Hello, I just coded a upload function for my site, only to discover that I
> can't copy files from /tmp directory to my directory as Apache is running
as
> user "nobody" and as such does not have write permission to my directory.
Yup.
> What can I do now? Is there any way to change the user of Apache through
php
> code?? Or is there any other way? Any suggestion will be greatly
> appreciated.
Running Apache as some other user is *possible*, but extremely dangerous.
Read httpd.conf, and you'll find the thing to change to make it happen, but
don't do it unless you *really* don't care about security.
A more realistic option would be to install PHP as a stand-alone binary (aka
"CGI") and wrap suExec (http://apache.org) around that, using a different
mime-type and extension (say .phpcgi and application/x-httpd-phpcgi) to
invoke *that* PHP, and then use that extension for your form upload. This
then allows a .phpcgi file to do anything *you* can do -- so you need to be
vigilant about the permissions/existence of any files named *.phpcgi for
security reasons, or any httpd.conf or .htaccess alterations of files to be
executed as if they were .phpcgi files (ie, running with your permissions).
Another possibility is to create a shell script, or Perl script, or even a
PHP script executed by the PHP binary above, just like a Perl script, that
is owned by you, and can copy the files as needed from /tmp to your
directory.
You could just make a directory be writable by the world, as noted below,
but obviously security issues, depending on what you do with the files in
that directory, and who can read/execute said files, make this a Bad Idea in
most cases.
This was made difficult "on purpose", since to make it easy for you to copy
files from /tmp to your own directory with your own user owning them would
be a pretty nasty security hole.
Yes, it sucks, but having your server be trashed sucks more.
> I just also found out that I can write to one of the directories if I set
> its permission to 775 but not to others. I can only do it with permission
> 777. Why?
Because user "nobody" owns that directory, or is in the group that owns the
directory? It could be that somebody has anticipated this problem, and has
created that directory and its ownership specifically so that you can do
what you're trying to do.
cd to that directory, and then cd .. (one up from it). Then do "ls -als |
less" and look carefully at the owner and group on that directory.