Need help with permissions!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Need help with permissions!

Post by DrT »

I am trying to get a script running on my host that creates or overwrites a small text file on my hosts web server. I am using the command fp$=fopen("test.txt", "w") and all I get back is the error Warning: fopen("test.txt", "w") - Permission denied in /usr/local/psa/home/vhosts/milltech-php.com/httpdocs/scripts/submit.php on line 9

If I use the "r" parameter instead then its quite happy!

The system is running PHP v4.1.0 on Apache and phpinfo.php returns the following for configuration " './configure' '--with-apxs=apxs' '--prefix=/home/builder/psa-dummies/psa/apache/../release/usr/local/psa/apache' '--with-system-regex' '--with-config-file-path=/usr/local/psa/apache/conf' '--disable-debug' '--disable-pear' '--enable-sockets' '--enable-track-vars' '--without-gd' '--with-mysql=/home/builder/psa-dummies/psa/apache/../release/dist/usr/local/psa/mysql' '--with-iodbc=/home/builder/psa-dummies/psa/apache/../release/lib/libiodbc' '--with-imap=/home/builder/psa-dummies/psa/apache/../release/lib/imap-cclient'"

Any help you might be able to give me to tell me whats going wrong or what permissions aren't right here would make me extremely gratefull!

Thanks

Tim west
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

most likely the permission on that file are r-xr-xr-x when they need to/should be rwxrwxrwx. so try doing this:

chmod 777 test.txt

that should make everything a-okay
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Can't be just that!

Post by DrT »

Thanks for the thought but when I first fire up the script the file doesn't actually exist so there's nothing to set the permissions on! I was hoping that the script would actually create the file 'cos thats what the book says the "w" parameter will do :(
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

try doing the chmod command on the containing directory. could be that the directory is not set to allow the PHP engine to create files, but since you own it, its not that hard of a problem to fix
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Thanks

Post by DrT »

Thanks, I was just coming to that conclusion my self. I'll give it a try.

Tim west
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post by enygma »

btw - 777 is a very scary permission to set.
Here's a brief overview:

1 - exe
2 - write
4 - read

order: user/group/world (done in groups of three - rwx)

so that, if you wanted to make it full permissions for the user that owns it:
-rwx------
or
1+2+4 = 7 so .... chmod 700 filename

or, to make it read only for everyone, and allow only the user to write to it:
-rw-r--r--
or
4+2 = 6
4 (read) so..... chmod 644 filename
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

yeah, its scary but alot of servers run their httpd as user 'nobody' and therefore needs global access to modify the files.mine is setup that way and im guessing that DrT's is set up that way as well.
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Post by DrT »

Yep, that was my problem and now I can write to a file! Thanks guys!
Post Reply