Home > Archive > PHP Programming > February 2005 > PHP Scripts and Creating Files
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
PHP Scripts and Creating Files
|
|
| Bryan Meyer 2005-02-23, 3:56 am |
| Hello Everyone:
I have a PHP script that attempts to create a temporary file to be used
during processing. The script is owned by my username (bryanrme) on
the server. When the script attempts to create the temporary file, I
get a "failed to open stream: Permission denied" error. The
permissions on my directory are set to 755. When I set the permissions
to 757, the creation of the file is successful. In this case, I notice
that the script spawns a temporary file owned by a user named "99".
Is there any way to avoid this? I'd prefer not to leave my directory
set at 757, but is there any workaround for this? I checked my server
configuration and safe mode is not enabled. Any suggestions? I would
prefer that the script handle the creation, usage, and disposable of
the temporary file.
Thanks,
Bryan
| |
| Geoff M 2005-02-23, 3:56 am |
| brmeyer@gmail.com says...
> I have a PHP script that attempts to create a temporary file to be used
> during processing. The script is owned by my username (bryanrme) on
> the server. When the script attempts to create the temporary file, I
> get a "failed to open stream: Permission denied" error. The
> permissions on my directory are set to 755. When I set the permissions
> to 757, the creation of the file is successful. In this case, I notice
> that the script spawns a temporary file owned by a user named "99".
>
> Is there any way to avoid this? I'd prefer not to leave my directory
> set at 757, but is there any workaround for this? I checked my server
> configuration and safe mode is not enabled. Any suggestions? I would
> prefer that the script handle the creation, usage, and disposable of
> the temporary file.
(assuming you mean the script is run via a web interface and that this is
a Linux/Apache setup)
PHP runs scripts under the umbrella of the apache user (looks like this is
user 99 in your setup) with the permissions/etc for that user.
Set up a user group with both (and only) yourself and the apache user as
members. Set the directory's group ownership to this group (leave the
directory's personal ownership as yourself). Set directory permissions to
775.
Geoff M
| |
| Bryan Meyer 2005-02-25, 3:56 am |
| Geoff:
Thanks for the advice. Unfortunately, it is not my server. I purchase
hosting. I access my settings through the cPanel interface, so I'm not
sure if there is any way to follow the instructions you gave me. Is
there a way?
Bryan
| |
| Geoff M 2005-02-25, 3:56 am |
| brmeyer@gmail.com says...
> Thanks for the advice. Unfortunately, it is not my server. I purchase
> hosting. I access my settings through the cPanel interface, so I'm not
> sure if there is any way to follow the instructions you gave me. Is
> there a way?
Bryan,
If your willing to try ....
Use the SSL Shell/Telnet shell access button (near bottom of cPanel page?)
and when you have logged in and have a command line prompt and type in:
groups 99
to see the list of user groups that the user named 99 (which Apache/PHP
appears to be running as) belongs to.
Then type in:
groups <your account name>
and see what groups you are in.
If you're lucky, there might be a group common to you both. Even if not,
you could still just pick a group that user 99 belongs to (less secure,
but hey, still better than world writable) and you may be able to set the
directory's group ownership to that group.
To see who might be members of a group, type in:
cd /etc/
then type in
more group | grep <group name>
Navigate to one level above the relevant directory:
cd /<path to your directory>/
Typing in:
ls -al
will give you details of directories and files including their user and
group ownership settings.
You can leave the relevant directory personally owned by you and just
change the group ownership by typing:
chgrp <group name> <directory name>
Again type:
ls -al
to check that the change has worked, then type:
chmod 775 <directory name>
and then PHP will be able to write to the directory.
G
|
|
|
|
|