PHP Scripts and Creating Files

This is a discussion on PHP Scripts and Creating Files within the PHP Language forums, part of the PHP Programming Forums category; Hello Everyone: I have a PHP script that attempts to create a temporary file to be used during processing. The ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-23-2005
Bryan Meyer
 
Posts: n/a
Default PHP Scripts and Creating Files

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

Reply With Quote
  #2 (permalink)  
Old 02-23-2005
Geoff M
 
Posts: n/a
Default Re: PHP Scripts and Creating Files

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
Reply With Quote
  #3 (permalink)  
Old 02-25-2005
Bryan Meyer
 
Posts: n/a
Default Re: PHP Scripts and Creating Files

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

Reply With Quote
  #4 (permalink)  
Old 02-25-2005
Geoff M
 
Posts: n/a
Default Re: PHP Scripts and Creating Files

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0