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 315509
In Process

The Archive Base Latest Questions

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

I have set file permissions to 777 yet I cannot write to the file

  • 0

I have set file permissions to 777 yet I cannot write to the file with PHP.

I can clearly see in my FTP client that the file has 0777 permissions and when I do:

echo (true === is_writable('file.txt')) ? 'yes' : 'no';

I get ‘no’;

I also tried:

echo (true === chmod('file.txt', 0777)) ? 'yes' : 'no';

With the same result.

The directory listing goes something like this:

public_html
    public          0777
        css         0755
        js          0755
        file.txt    0777

And I’m using .htaccess file to redirect all traffic to the public subfolder. Of course, I have excluded the file from rewriting (it is accessible from the browser I checked):

RewriteRule  ^(file).*  - [L]

Why is that?

  • 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-12T08:17:53+00:00Added an answer on May 12, 2026 at 8:17 am

    I guess Apache runs as a different user/group than the user/group owning the file. In which case, the file itself needs to be 0777.

    public only needs to be 0777 if you plan on adding files to the folder using PHP. Even if the folder itself is not 0777, if the file is and the folder has at least 5 for the user (read/execute), you should be able to write to the file.

    In the end, your file tree should look like this:

    public_html
        public
            file.txt  0777
    

    Naturally, you won’t be able to change those permissions using PHP, but you can do so from your FTP client.

    If it still isn’t working, PHP might be running in safe mode or you might be using an extension such as PHP Suhosin. You might get better result changing the owner of the file to the same user/group that is running the script.

    To get the user/group id of the executing user, you may use the following:

    <?php
    echo getmyuid().':'.getmygid(); //ex:. 0:0
    ?>
    

    Then, you may use chown (in the terminal) to change the owner of the file:

    > chown 0:0 file.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a php file to run that just echos hello. <?php
I have read this:- Why can't PHP create a directory with 777 permissions? and
I have set an array in my config file that I use global in
I currently have a .htaccess file set up with this rule: RewriteRule ^([a-zA-Z0-9_-]+)$ user\.php?user=$1
I have a problem with file permissions on executing files in Windows that seems
I have a PHP script which changes file permissions on my server using chmod.
It seems i cannot create files. When i set permissions to 777 On the
I have a little problem because on my website I can't really set permissions
I have set of flat files (114 files) each file is named with database
I have set the two buttons in preference.xml file. I want to go to

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.