Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 307689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:34:53+00:00 2026-05-12T07:34:53+00:00

I’ve run into an issue moving onto my test (and tried it on prod,

  • 0

I’ve run into an issue moving onto my test (and tried it on prod, no go) where I have a php script create a file and put some data in that file.

I’ve set the permissions to R, W, X for “Owner, Group, Other” using winSCP (i’m not much for commandline yet).

What i can see is that the script is able to create the file (i’ve deleted, and it recreates the files properly every time), but the exact same script can’t write to the file and I get a permission error.
“failed to open stream: permission denied”

Here’s the script that I’m using,it worked in windows, but now on linux, no go.

Any ideas?


$type='get';

$count_my_page = ("list".$counterDate.".txt");
if(!file_exists($count_my_page)){
$fp=fopen($count_my_page, "w");
$putArray=array($type=>'1');
$putJson=json_encode($putArray);
fputs($fp, $putJson);
fclose($fp);
} else {

$hits = file($count_my_page);
if(empty($hits)){
    $putArray=array($type=>'1');
$putJson=json_encode($putArray);

} else {
    $putArray=json_decode($hits[0], true);
    if(!array_key_exists($type, $putArray)){
        $putArray[$type] = '1';


    } else {

        $hit=$putArray[$type];

        $putArray[$type]++;

    }
}
$putJson=json_encode($putArray);
$fp=fopen($count_my_page, "w");
fputs($fp, $putJson);
fclose($fp);

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:34:54+00:00Added an answer on May 12, 2026 at 7:34 am

    Creating a file requires write permission on the directory (that is probably what you set with winscp ?).

    But modifying a file requires write permissions on the file itself.

    To give such permissions to Apache, you might have to use the function chmod after you’re done creating the file.

    Something like this might do, I suppose :

    chmod($count_my_page, 0666);
    

    6 = 4 (read) + 2 (write).

    You don’t need to give execution (1) privilegies.

    Does this help ?

    And I supposed it worked on windows because Apache run as your user (or as administrator) — or because Windows’ permission system is more permissive

    Edit : for more details about permissions under Linux, you might what to take a look at this part of the corresponding Wikipedia article (quoting) :

    There are three specific permissions
    on Unix-like systems that apply to
    each class:

    • The read permission, which grants the ability to read a file. When set
      for a directory, this permission
      grants the ability to read the names
      of files in the directory (but not to
      find out any further information about
      them, including file type, size,
      ownership, permissions, etc.)
    • The write permission, which grants the ability to modify a file. When set
      for a directory, this permission
      grants the ability to modify entries
      in the directory.
      This includes
      creating files, deleting files, and
      renaming files.
    • The execute permission, which grants the ability to execute a file. This
      permission must be set for executable
      binaries (for example, a compiled c++
      program) or shell scripts (for
      example, a Perl program) in order to
      allow the operating system to run
      them. When set for a directory, this
      permission grants the ability to
      traverse its tree in order to access
      files or subdirectories, but not see
      files inside the directory (unless
      read is set).

    You could also have fun with umask, but I’ve always prefered calling chmod when it’s necessary (and only when it’s necessary : I prefer not giving too much permissions — more secure this way) — and umask may have some problems with some servers, if I remember correctly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.