Solved

Give PHP writeaccess

Posted on 2004-09-25
19
832 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
 
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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now