i have read a lot about the fopen permission denied error. But i am not able to find a solution. I am aware that this is a permission problem. Please have a look at my settings and what i have done so far to solve the problem:
Almalinux 9
/var/www/html
in /var/www/html i have script called testing.php and in the subdirectory /var/www/html/upload/tmp/ there exists a file called readtest.csv
This is the code:
<php>
$filename = "/var/www/html/upload/tmp/readtest.csv";
$handle = fopen($filename,"r");
$filename = "/var/www/html/upload/tmp/writetest.csv";
$handle = fopen($filename,"w");
echo exec("whoami");
</php>
If i run the script it can read the readtest.csv file without any errors. But if i try to write the file writetest.csv it show “permission denied”.
The result of whoami is “apache”
I open a shell logged in as root and run:
sudo chown -R apache /var/www/html
The owner of the folder and the owner of the file is “apache”
I checkd running
ls -la in /var/www/html/upload/tmp/
drwxr-xr-x. 3 apache apache 43 10. Jan 10:42 tmp
But i am unable to write from the php script to this directory. But i am the owner! I dont know where to look next to solve the problem?
Why apache can not write to its own directory?