Article 5HECH PHP file will not open because of wrong permissions - in firefox browser

PHP file will not open because of wrong permissions - in firefox browser

by
pizzipie
from LinuxQuestions.org on (#5HECH)
Despite several manipulations of owner, group, and other permissions I can't get php to open/create a file.

Here is a complete test script to show what is going on.

Code:<!DOCTYPE HTML>

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html"; charset="UTF-8" />
<title> OptumRx Log 14Aug2020, 28Sep2020, 04May2021</title>

</head>
<body>

<div class="header">

<h1>Test script to open - optumRx.php - file</h1>
</div> <!--header-->

<div class="container">

<?php // =================== PHP ============================

error_reporting (E_ALL ^ E_NOTICE);
//include('../include/myPhpFunctions.inc');

$log='optumRx.log';
$timezone="America/Los_Angeles"; // see mytimestamp() in myPhpFunctions.inc
$format="D M d, Y";
$incTime=true;

echo mytimestamp($timezone);
echo "<br><br>user ... ".exec(whoami)."<br>";
echo "<br>File permissions: <br>";
echo "-rwxrwxr-- 1 www-data rick 1434 May 4 12:04 insertQuery.php<br><br>";
echo "drwxrwsr-x 7 rick rick 4096 May 3 16:51 DBases OR<br>";
echo "drwsrwsr-x 7 rick www-data 4096 May 3 16:51 DBases OR<br>";
echo "drwsrwsr-x 7 www-data rick 4096 May 3 16:51 DBases<br><br>";
echo "drwxrwsr-x 14 rick rick 4096 May 3 13:26 Dbmysql<br><br>";

echo "APACHE2 error.log:<br>";
echo "PHP Warning: fopen(optumRx.log): failed to open stream:";
echo "Permission denied in /home/rick/DBases/Dbmysql/optumRx/insertQuery.php on line 36<br><br>";


echo '$fh=fopen($log, "a+") says ...<br>';

if(!($fh=fopen($log, "a+"))) die("CAN NOT OPEN LOG FILE"); // log database insert operations
$permission=substr(sprintf("%o", fileperms($log)),-4)."\n";
echo "permission ... ".$permission;
if($permission !="0660") {
chmod($log,0660);
chown($log, "www-data:rick");
clearstatcache();
}
fwrite($fh, "# ".mytimestamp($timezone)."\n\n"); // see line 9
fwrite($fh, $query."\n\n"); // write insert to log
fwrite($fh, "# ========================================================\n");
fclose($fh);


function mytimestamp($tzone) {
date_default_timezone_set($tzone);
return date('D, M d, Y H:i:s');
}

?> <!-- ================= HTML ============================ -->

</body>
</html>RESULT:
Quote:
Test script to open - optumRx.php - file
Tue, May 04, 2021 12:54:49

user ... www-data

File permissions:
-rwxrwxr-- 1 www-data rick 1434 May 4 12:04 insertQuery.php

drwxrwsr-x 7 rick rick 4096 May 3 16:51 DBases OR
drwsrwsr-x 7 rick www-data 4096 May 3 16:51 DBases OR
drwsrwsr-x 7 www-data rick 4096 May 3 16:51 DBases

drwxrwsr-x 14 rick rick 4096 May 3 13:26 Dbmysql

APACHE2 error.log:
PHP Warning: fopen(optumRx.log): failed to open stream:Permission denied in /home/rick/DBases/Dbmysql/optumRx/insertQuery.php on line 36

$fh=fopen($log, "a+") says ...
CAN NOT OPEN LOG FILE
Hope someone can steer me in the right direction to solve this as it is very frustrating!latest?d=yIl2AUoC8zA latest?i=b8DmeNBGL6s:XiQ5icR0B0M:F7zBnMy latest?i=b8DmeNBGL6s:XiQ5icR0B0M:V_sGLiP latest?d=qj6IDK7rITs latest?i=b8DmeNBGL6s:XiQ5icR0B0M:gIN9vFwb8DmeNBGL6s
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments