[SOLVED] PHP file will not open because of wrong permissions - in firefox browser
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
PHP file will not open because of wrong permissions - in firefox browser
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!
drwxrwsr-x 14 rick rick 4096 May 3 13:26 Dbmysql
PHP Warning: fopen(optumRx.log): failed to open stream:Permission denied in /home/rick/DBases/Dbmysql/optumRx/insertQuery.php on line 36
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.