samedi 31 janvier 2015

PHP runing from Apache cannot write to filesystem

I cannot make PHP write a file to filesystem when running from Apache webserver.


I have a simple PHP script:



<?php
print 'User : '.posix_getpwuid(posix_getuid())['name'];
print ' ';
print 'Group: '.posix_getgrgid(posix_getgid())['name'];
file_put_contents('./test.txt', 'OK');
?>


I'm logged in as user ec2-user:ec2-user and just for testing Apache is running as ec2-user:ec2-user.


ec2-user belongs to the following groups:



>groups
ec2-user adm wheel systemd-journal www


The script is located in Apache document root.



/var/www/html/test.php

drwxr-xr-x. 21 root root 4096 ene 31 05:45 var
drwxrwsr-x. 4 root www 31 ene 29 17:30 www
drwxrwsr-x. 2 root www 36 ene 31 06:16 html
-rw-rw-r--. 1 ec2-user www 172 ene 31 06:15 test.php


If a run the script vis PHP cli the file test.txt is created and the following output is generated.



>php ./test.php
User : ec2-user Group: ec2-user


But if I call the script via my browser as a normal web page, I get a file permissions error:



User : ec2-user Group: ec2-user
Warning: file_put_contents(./test.txt): failed to open stream: Permission denied in /var/www/html/test.php on line 6


I have tried also to run Apache as ec2-user:www, but the output is the same:



User : ec2-user Group: www
Warning: file_put_contents(./test.txt): failed to open stream: Permission denied in /var/www/html/test.php on line 6


I have checked PHP configuration and there is no open_basedir option configured.


I have tried to write to a /dummy folder with 777 permissions and the same output.


Is there any configuration I'm missing?





Aucun commentaire:

Enregistrer un commentaire