473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

fopen() Permission denied

I have created the file lhcount.data with the content the number 1 in
it.
This file is in the same directory (public_html) as the following
index.php file that contains the following code:

<?php
echo("count");
$fh = fopen('lhcount.data','r+');

result is:
count
Warning: fopen(lhcount.data): failed to open stream: Permission denied
in /home/abc/public_html/index.php

The permissions are:
public_html directory rwxrwx- - -
lhcount.data rwxrwxr- -
index.php rw-r- -r- -

phpadmin() shows the following:
safe_mode is off
open_basedir has no value set

I'm at a loss. I have used this with success at another web host.

Thanks for any advice.
Lee Haas, Raleigh, NC
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Email may be sent to me by using:
http://tinyurl.com/fylz
Feb 17 '06 #1
8 36636
Dans son message précédent, Lee C. Haas a écrit :
I have created the file lhcount.data with the content the number 1 in
it.
This file is in the same directory (public_html) as the following
index.php file that contains the following code:

<?php
echo("count");
$fh = fopen('lhcount.data','r+');

result is:
count
Warning: fopen(lhcount.data): failed to open stream: Permission denied
in /home/abc/public_html/index.php

The permissions are:
public_html directory rwxrwx- - -
lhcount.data rwxrwxr- -
index.php rw-r- -r- -

phpadmin() shows the following:
safe_mode is off
open_basedir has no value set

I'm at a loss. I have used this with success at another web host.


Please copy/paste the output of this piece of code :

<?
echo 'Id: ' . getmyuid() . '<br />';
echo 'Gid: ' . getmygid() . '<br />';
echo '<br />';
echo nl2br(print_r(stat('index.php'), true));
?>
--
Julien CROUZET - DSI Theoconcept
julien.crouzet@/enlever ca\theoconcept.com
http://www.theoconcept.com
Feb 17 '06 #2
Il se trouve que Julien CROUZET a formulé :
Please copy/paste the output of this piece of code :

I meant :

<?
echo 'Id: ' . getmyuid() . '<br />';
echo 'Gid: ' . getmygid() . '<br />';
echo '<br />';
echo nl2br(print_r(stat('lhcount.data'), true));
?>

Sorry for that.

--
Julien CROUZET - DSI Theoconcept
julien.crouzet@/enlever ca\theoconcept.com
http://www.theoconcept.com
Feb 17 '06 #3
You should allow your public_html directory to be searchable by all.

chmod 755 public_html.

If that doesn't work, do ls -al to figure out your username/group
ownerships. If the server HTTP process is not running as one of those
then your user/group permissions don't really matter because the only
way it will be able to read/write from that file will come from the
"world" permissions.

Alex
http://prepared-statement.blogspot.com

Feb 17 '06 #4
On Fri, 17 Feb 2006 20:29:55 +0100, "Julien CROUZET"
<julien.crouzet@/enlever ca\theoconcept.com> wrote:
Il se trouve que Julien CROUZET a formulé :
Please copy/paste the output of this piece of code :

<?
echo 'Id: ' . getmyuid() . '<br />';
echo 'Gid: ' . getmygid() . '<br />';
echo '<br />';
echo nl2br(print_r(stat('lhcount.data'), true));
?>


I added php to the <? at the start.

Below are the results of the code you gave me. Am I an idiot for
responding with data that should not be made public?

I do not know what to do with this information.
Thank you for your interest.

- Lee

Id: 32006
Gid: 507

Array
(
[0] => 771
[1] => 5980982
[2] => 33188
[3] => 1
[4] => 32006
[5] => 507
[6] => 0
[7] => 3923
[8] => 1140231574
[9] => 1140231540
[10] => 1140231541
[11] => 4096
[12] => 8
[dev] => 771
[ino] => 5980982
[mode] => 33188
[nlink] => 1
[uid] => 32006
[gid] => 507
[rdev] => 0
[size] => 3923
[atime] => 1140231574
[mtime] => 1140231540
[ctime] => 1140231541
[blksize] => 4096
[blocks] => 8
)
Lee Haas, Raleigh, NC
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Email may be sent to me by using:
http://tinyurl.com/fylz
Feb 18 '06 #5
Do as Alex said before. Chmod to 755. The reason the file can't be
opened is because apache, which usually runs as user nobody (is the
user that will open the file). The way you have your permissions set
only you and users that are part of your group have read / write access
to your directory and lhcount.data.

Feb 18 '06 #6
On 17 Feb 2006 13:48:32 -0800, "Alex" <sp*******@gmail.com> wrote:
You should allow your public_html directory to be searchable by all.
chmod 755 public_html.
...
Alex


Thanks Alex and "samudasu," changing permissions was the key.

I had to change
lhcount.data to 766
public_html directory to 750

I don't understand why it didn't have to be 755 (which also worked)
and I don't understand why index.php worked with permissions 644.
index.php has the php code in it and I would have thought it would
need "execute" permission.
Is this explained clearly somewhere?

Following I is the complete php script I am using for a simple text
counter.

<SPAN style="float : right; color : #999999;">
<?php
/* The file lhcount.data with an initial number must be created in
the same directory as the file with this script */
$fh = fopen('lhcount.data','r+');
$Count=fgets($fh,64);
rewind($fh);
fwrite ($fh, ++$Count);
fclose ($fh);
echo($Count);
?>
</SPAN>

Thanks for the help.
Lee Haas, Raleigh, NC
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Email may be sent to me by using:
http://tinyurl.com/fylz
Feb 18 '06 #7
Lee C. Haas wrote:
On 17 Feb 2006 13:48:32 -0800, "Alex" <sp*******@gmail.com> wrote:

You should allow your public_html directory to be searchable by all.
chmod 755 public_html.
...
Alex

Thanks Alex and "samudasu," changing permissions was the key.

I had to change
lhcount.data to 766
public_html directory to 750

I don't understand why it didn't have to be 755 (which also worked)
and I don't understand why index.php worked with permissions 644.
index.php has the php code in it and I would have thought it would
need "execute" permission.
Is this explained clearly somewhere?

Following I is the complete php script I am using for a simple text
counter.

<SPAN style="float : right; color : #999999;">
<?php
/* The file lhcount.data with an initial number must be created in
the same directory as the file with this script */
$fh = fopen('lhcount.data','r+');
$Count=fgets($fh,64);
rewind($fh);
fwrite ($fh, ++$Count);
fclose ($fh);
echo($Count);
?>
</SPAN>

Thanks for the help.
Lee Haas, Raleigh, NC
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Email may be sent to me by using:
http://tinyurl.com/fylz


index.php is not an executable program. It's only a script - which is
processed by the php interpreter (php or php.exe), which is an executable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 18 '06 #8
On 2006-02-18, Lee C Haas <Nu**@Address.org> wrote:
On 17 Feb 2006 13:48:32 -0800, "Alex" <sp*******@gmail.com> wrote:
You should allow your public_html directory to be searchable by all.
chmod 755 public_html.
...
Alex
Thanks Alex and "samudasu," changing permissions was the key.

I had to change
lhcount.data to 766
public_html directory to 750

I don't understand why it didn't have to be 755 (which also worked)


In your case the web server may have the same group as the directory.
and I don't understand why index.php worked with permissions 644.
index.php has the php code in it and I would have thought it would
need "execute" permission.
Is this explained clearly somewhere?
php scripts don't need execute because they aren't run by name (constrast
with shell scripts) but instead they are run by invoking php to interpret
them (or using a webserver plugin etc)
Following I is the complete php script I am using for a simple text
counter.

<SPAN style="float : right; color : #999999;">
<?php
/* The file lhcount.data with an initial number must be created in
the same directory as the file with this script */
$fh = fopen('lhcount.data','r+');
$Count=fgets($fh,64);
rewind($fh);
fwrite ($fh, ++$Count);
fclose ($fh);
echo($Count);
?>
</SPAN>


lhcount data doesn't need owner exec permission 666 would be OK.
600 or 644 would be better if you can adjust the user-id to match that of the
webserver.

Bye.
Jasen
Feb 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marc | last post by:
Hello, when using flock() I get a permission denied error: Warning: fopen("<filename>", "r+") - Permission denied in <pathtofile> on line 7 I do this: $fileToOpen=substr($PHP_SELF,...
1
by: JaazzMan | last post by:
Hi! I wrote this script and executed on my server, with php 4.1.2 <?php $fp = fopen('test.txt', 'w'); fwrite($fp, "Bla bla"); fclose($fp); ?> it returns this message:
0
by: glesaux | last post by:
Hi, In one of my script i'm trying to apend a daily log file (see script part bellow). When the script runs, this message appears : fopen(temp/pglog.20050106.log): failed to open stream:...
9
by: bird | last post by:
What can cause the PHP code fopen("filename","a") to fail with permission denied message as below? ------------------ Warning: fopen(filename): failed to open stream: Permission denied in...
3
by: fAnSKyer | last post by:
I am trying to make a new file using fopen, but I got a exception: failed to open stream: Permission denied in tmp/ .. I am using linux and I've already chmod the php file to 777. I tried...
1
by: doctorhardik | last post by:
other interesting thing i observe during my work which i describe below: i am using dotproject2.0.4 on fc3. it is working fine. but i want to generate pdf file report during this time i face...
3
gagandeepgupta16
by: gagandeepgupta16 | last post by:
hi I need urgent help on this please.... i am a newbie in PHP. i am using php on windows and IIS 5.1 i am working on counter module for website... i have a text file that contains the...
2
by: swethak | last post by:
Hi, when i run my code it gives error as fopen(lib/providers//provider.RVLogic.php): failed to open stream: Permission denied in F:\Facebook\furniture11\Data...
2
by: gowthamkg | last post by:
Hi All, I Have Installed Wamp Server In My System.....i Have Written A Simple Php Program To Read And Display The Details Inside A File...so I Used Fopen...but The Output Is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.