LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2021, 03:06 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
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!

Last edited by pizzipie; 05-04-2021 at 03:08 PM.
 
Old 05-04-2021, 07:25 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Probably this...

Code:
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
 
Old 05-04-2021, 07:53 PM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
that is what I have now.
 
Old 05-04-2021, 08:08 PM   #4
uteck
Senior Member
 
Registered: Oct 2003
Location: Elgin,IL,USA
Distribution: Ubuntu based stuff for the most part
Posts: 1,173

Rep: Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501Reputation: 501
You have permissions set for DBases, but what about the files and directories under it? www-data may not be able to see anything else.
 
Old 05-04-2021, 09:26 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by pizzipie View Post
that is what I have now.
Yes, but my point is that www-data cannot write to a directory with those permissions...

If the apache/php processes need to write down that path, perhaps:

Code:
chown -R rick:www-data DBases/

Last edited by astrogeek; 05-07-2021 at 12:02 AM. Reason: typso
 
Old 05-08-2021, 12:04 PM   #6
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
I found this site and followed the suggestions - now works.

https://appuals.com/how-to-fix-forbi...ing-up-apache/

Thanks for your help!

R
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What determines whether firefox will open a file (PHP or HTML) in the browser pizzipie Programming 9 07-29-2020 08:37 PM
[SOLVED] Is there a browser than can be set up to open links in another browser such as firefox? Ulysses_ Linux - Software 12 09-14-2018 02:23 PM
Trace file not generating (ns2 ) because wrong code ? aroneasadas Linux - Newbie 1 04-16-2018 08:05 AM
[SOLVED] Install php-xml fails because php-common is too recent (maybe) trentham Linux - Software 1 08-05-2014 09:28 AM
cannot login because file system check fails because of bad magic number trutnev Linux - Newbie 1 03-23-2004 06:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration