Function.fopen: Could not open stream: Permission denied in PHP

I am trying to create XML sitemaps for my website from my PHP application. The idea is to either create a new file or overwrite an existing file. When I call fopen, I get the following error:

[function.fopen]: failed to open stream: Permission denied

I am trying to write webroot and its permissions: 755. This means that the owner has write permission, right? What do I need to do so that my script can write to this folder? 777 would be bad, right? Can I run my script as the owner?

Thank.

+5
source share
7 answers

, , 777 . - , .

:

  • Sitemap cronjob, , apache.
  • Sitemap a 302 Redirect . , , - sitemap.xml, , (, PHP, ).
  • sitemap.xml php script, XML.

!

+5

, . Ubuntu linux w/php apache

  • php script w/: <?php exec('whoami'); ?> . , script
  • SSH .
  • , , .
  • , , .
  • , , , .
  • Apache: sudo apachectl restart

, :

+5

ACL webroot, -.

setfacl -m u:apache:rwx /var/www/html

apache - /var/www/html -.

+1

, apache nobody

,

useradd -G nobody youruser

chown -R youruser:nobody .

0775

chmod -R 0775 .

useradd -G nobody yourgroup

+1

777 , PHP , PHP, Apache .. , - , / .

0

(.. 775)? , . PHP ( www-data) , , 775 ( 774).

0

! apache

<?php exec'whoami'; ?>

useradd -G username username2
chown -R username:username2 .
chmod -R 0775 .

! !

0

All Articles