views:

633

answers:

5

I'm trying to launch PHP site with apache on fedora and I have a problem about writting permissions. It looks like apache does not have write permissions to some folders, but I canno understand why.

I've checked httpd.conf and it has group: apache, user: apache. I then made: chown -R apache:apache www and set 777 permissions to the folders, but it still says:

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

Please advice.

UPDATE: Btw, if I make "php newtest.php" from command line, the file temp.txt is created with group root and user root. It just doest not work from the browser.

A: 

make chmod 775 to newtest.php ;)

Amad
As I already mentioned, I made 777 to the entire folder (including newtest.php of course). temp.txt is a new file which I want to be created, it does not exist yet.
Pavel Dubinin
A: 

ls -la /var/www/public

Just to check :-)

Qwerty
Ok, the folder itself has this:drwxrwxrwx 8 apache apache 4096 2010-02-13 04:08 publicThe file I'm executing:-rwxrwxrwx 1 apache apache 213 2010-02-14 06:34 newtest.php
Pavel Dubinin
Weird. Are you sure that temp.txt is not already there?Also, what will happen if you try "sudo -u apache echo test > /var/www/public/temp.txt" ?
Qwerty
yes, it was not there. When I launced the command you suggested (under root), it have created it, but when I try my PHP script again, it still shows the same error even though the file is there. I'm certain it has something to do with apache permissions, but not sure what exactly..
Pavel Dubinin
Hmm. Other reasons could be safe_mode or open_basedir options enabled in php.ini or in apache config or in .htaccess. But I think they should produce slightly different warnings.
Qwerty
no.. this is not the case. both are off.
Pavel Dubinin
http://stackoverflow.com/questions/1870875/php-cannot-write-to-file-even-though-it-has-777-permissions - maybe same issue? :-)
Qwerty
nope, I'm running ext3 if you meant filesystem issue.
Pavel Dubinin
I'm about to give up :-)Crazy idea: maybe you didn't restart apache and it's running under nobody's rights? Try system('id') from your script :-)
Qwerty
no, it's running as apache user and group, I've just rechecked that from php. I'm sort of confused myself...
Pavel Dubinin
Qwerty
I already did 0777 to the entire tree.. is_readable returns true, is_writable returns false.
Pavel Dubinin
A: 

have you tried to touch temp.txt and just change file_put_contents() and add FILE_APPEND flag?

f13o
Any file operation gives permission error, so it does not matter what I do: file_put_contents, fwrite, imagepng - all give similar errors. touch returned this: Warning: touch() [function.touch]: Utime failed: Permission denied in /var/www/public/newtest.php on line 6
Pavel Dubinin
I meant shell touch command...
f13o
anyway this does not help. and I need to be able to create files, not just modify it.
Pavel Dubinin
Turn off SELinux ?
f13o
A: 

I'd recommend switching apache to mod_itk as mpm and running the particular vhost with permissions of the owner document root directory and contained php scripts.

hurikhan77
how should this help with my issue? I don't really need vhost here..
Pavel Dubinin
In Apache there is at least a default vhost configured usually. You probably want to try to set the vhost owner there. But you probably also want to improve your question because mod_itk is overkill in single vhost setups and I would not have suggested it then. ;-)
hurikhan77
+1  A: 

Warning: file_put_contents(/var/www/public/temp.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/public/newtest.php on line 8

There is so much bad stuff here.

Lets start with the fact that you really want to keep httpd writeable files well away from your code - certainly in a seperate directory, preferably outside the document root altogether.

chown -R apache:apache www and set 777 permissions to the folders

And did you check afterwards what the permissions actually were? BTW see also the point above - if you've made your entire website writeable by the everybody then you're just asking for trouble. You certainly chouldn't change BOTH the owner AND the permissions.

Have you got SELinux enabled? (run sestatus as root). If so then you either need to disable it or learn how to configure it - but I'd recommend you get to grips with old-fashioned permissions first, then disable SELinux.

C.

symcbean
Ok, I know that 777 is not the way to store files, but in order to solve the problem I had to try everything. I've disabled SELinux now. sestatus root now shows "SELinux status: disabled", but the problem is still there :( Any ideas?
Pavel Dubinin
Ah no, actually it helped, just had the old file with root permissions here. thanks alot
Pavel Dubinin