Solved

Give PHP writeaccess

Posted on 2004-09-25
19
836 Views
Last Modified: 2008-07-03
I am running OSX 10.3.5 on a G4 PB.
I installed php5 and activated the in-built apache web server.

I activated personal websharing and put my site in my homedir:
~/Sites

Now, I have a script (residing in ./dominik/guestbook/ which needs to be able to WRITE in that directory. (It needs to be able to create new files!)

How do I do that?
I tried 'chmod -R 777 dominik/' to no success and 'chown -R www dominik/' which didn't change anything and just spit out an error. (No permission)

Any idea anybody?
Thanks,
Dominik
0
Comment
Question by:Daij-Djan
  • 8
  • 4
  • 4
  • +1
19 Comments
 
LVL 1

Expert Comment

by:x-tinct
ID: 12151093
Is safe mode turned on? Use phpinfo() to see what settings PHP use. To change edit php.ini.

If safe mode is turned on, php will only have write access to files/dirs with the same owner as the owner of the apache process (usually nobody on linux, don't know in OSX).

Read more about safe mode here:
http://no2.php.net/features.safe-mode
0
 
LVL 4

Expert Comment

by:Skonen
ID: 12151377
Will chmodding "dominik/" also give full access permissions to the guestbook directory? Trying to chmod /dominik/guestbook/ directly may be worth a try.
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 12151505
I did a chmod -r (so it is recursive and I checked the permissions... there a ok)
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:Daij-Djan
ID: 12151942
phpinfo says safemode is off!
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12152164
Check what user the webserver run as. (Type "ps aux" and look for httpd).
If the user is not nobody change nobody in the line under to correct username:

chown -R nobody:nobody ./dominik/guestbook/
0
 
LVL 4

Expert Comment

by:aratani
ID: 12153698
You have to set the apache user account as the owner of the file. Remember, php runs under apache; so whatever user account is running apache needs to get the access to the file (and get write permissions). Also, make sure you don't use root to run apache as this can cause huge secuirty problems. But, use a username like nobody or something similar.

AJ
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12153895
aratani: just what I said...
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 12154250
well... apache runs as www but chown isn 't working:
'chown: guestbook/: Operation not permitted'
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12154281
You will need to be the CREATOR of the directory or ROOT to be able to change the owner of the directory. In linux, type "su" then enter the root password to change the user to root.

Ok, since it's not running as user "nobody", you are probably not using the group "nobody" either. It is not really important. So ignore the group, and only change the owner:

Enter the command: "chown -R www ~/Sites/dominik/guestbook"
0
 
LVL 5

Author Comment

by:Daij-Djan
ID: 12154462
Well... changing the owner worked but still...
drwxr-xr-x   6 www      Dominik  204 17 Sep 22:43 guestbook

error] PHP Warning:  fopen("./guestbook/Dominik Pich.htm") [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /Users/Dominik/Sites/users/dominik/guestbook/add entry.php on line 66

I try to open the file with fopen w+
0
 
LVL 1

Accepted Solution

by:
x-tinct earned 63 total points
ID: 12154512
Are you sure you have the correct path for the guestbook. Take a look at the directory of the php file you are running:
/Users/Dominik/Sites/users/dominik/guestbook/add entry.php

Where is the guestbook lokated? Earlier you said it was here:
/Users/Dominik/Sites/dominik/guestbook

Make sure you changed the ownership of the right directory.
0
 
LVL 4

Assisted Solution

by:aratani
aratani earned 62 total points
ID: 12156583
I think you have got the ownership right if it shows what you said.

Probably, your fopen is going wrong. You are probably setting the wrong path in your fopen, since it trying to access the wrong file. Is this what you do,

fopen ("add entry.php", "w+");

I don't know how you've defined, but probably you've defined the fopen wrong.

Take care

AJ
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12493118
Hmm... aratani said just the same as I did in both of his answers. Just in other words.
0
 
LVL 4

Expert Comment

by:aratani
ID: 12494728
No I didn't .. my second answer was very different .. ;)

Abhishek (AJ) Ratani
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12513310
I don't want a fight about points. But facts are facts:

aratani: I think you have got the ownership right if it shows what you said.
Yes, Daij-Djan said it himself: "changing the owner worked"

aratani: You are probably setting the wrong path...
Yes, I already said that: "Are you sure you have the correct path..."

So what new ideas did you come up with?
0
 
LVL 4

Expert Comment

by:aratani
ID: 12513636
No I'm sorry I believe I am entitled to some points,

This is what I said that was different from you, if that is all you care about,

1. I don't know how you've defined, but probably you've defined the fopen wrong.

2. Also, make sure you don't use root to run apache as this can cause huge secuirty problems.

3. Remember, php runs under apache; so whatever user account is running apache needs to get the access to the file (and get write permissions)

4. Basically, I gave more detailed explanations about the situation and what might be causing the problem.

I don't mind it if the author decides to award somebody the points. But, I agree with the split if the author has nothing to say.

AJ
0
 
LVL 1

Expert Comment

by:x-tinct
ID: 12516884
1. Yes, he defined the fopen with the wrong PATH
2. True, but later he said apache runs as www, so this isn't part of the solution
3. I already said that (Check what user the webserver run as...)
4. True, but you still said the same things in other words

I don't want to argue more about these points, just split them!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question