Apache + PHP writes unix permissions

I am trying to run a PHP site with apache on Fedora, and I have a permission issue. It looks like apache does not have write permissions to some folders, but I cannot understand why.

I checked httpd.conf and it has a group: apache, user: apache. Then I did: chown -R apache: apache www and set 777 permissions for folders, but it still says:

Warning: file_put_contents (/var/www/public/temp.txt) [function.file-put-contents]: stream could not be opened: permission denied in /var/www/public/newtest.php on line 8

Please advice.

UPDATE: Btw, if I do "php newtest.php" from the command line, the temp.txt file is created using the root and root user. It just doesn't work from the browser.

+3
source share
5 answers

Warning: file_put_contents (/var/www/public/temp.txt) [function.file-put-contents]: stream could not be opened: permission denied in /var/www/public/newtest.php on line 8

There is so much bad here.

Let's start with the fact that you really want to save files that can be written in the httpd format, far from your code - of course, in a separate directory, preferably outside the root directory of the document.

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

And you checked what the permissions really were? By the way, see Also the paragraph above - if you made the entire site writable to everyone, then you just ask for troubles. Of course, you will not change BOTH your owner and permission.

SELinux ? ( sestatus root). , , , , , SELinux.

.

+3

chmod 775 newtest.php;)

0

ls -la/var/www/public

: -)

0

temp.txt file_put_contents() FILE_APPEND?

0

apache mod_itk mpm vhost php.

0

Source: https://habr.com/ru/post/1732767/


All Articles