954,242 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How NOT to Require CHMOD 755 Permissions To Create, Write and Delete Files on Linux?

On my previous server and on some other hosts, I was able to write to files (for example with PHP) without having to chmod the files first.

Now I cannot, and files are required to be chmoded properly so I can write to them.

I cannot even touch() a file with PHP.

Is there any way to have this permissions removed?

I don't want to chmod the all thing, all I want is to change the configurations so I can fwrite() or file_put_contents() normally.

I's a dedicated un-managed server, so basically any advanced configurations can be done.

Please help! :icon_neutral:

Thank you in advance!

=IceBurn=
Light Poster
25 posts since Dec 2008
Reputation Points: 18
Solved Threads: 0
 

If you are running apache, I believe it runs as user apache, or as nobody.... you could in theory, make the php script setuid and run as someone with permission to write to the directory. However, this is pretty glaring security risk, but if you keep it contained, it shouldn't be too big of a problem.... I think though, that newer versions of *nix prohibit setuid on scripts (though, it might just be setuid to root on scripts.. which you should never do anywhere, but not sure).

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

Do you mean that you can't write files in directories you created with the shell? What exact permissions are the files at before you chmod them? 755 permission means read/write/execute for owner, and read/execute for everyone else, which must mean that the owner of the files/directories is the same user that's running apache...

>I think though, that newer versions of *nix prohibit setuid on scripts
>(though, it might just be setuid to root on scripts.. which you should
>never do anywhere, but not sure).
Yeah, virtually all versions of *nix prohibit setuid on shell scripts globally, and for all users, not just root.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

Hi, and thank you for your replies.

I can write to the files with PHP, but I cannot create them.

For example PHP states that if you use file_put_contents() it attempts to create the file if does not exist. In my old server it would create the file with no problems.

So, on the new server I can use file_put_contents() if the file exists, but not when the file does not exist.

I believe the default permissions of the server for new files is 644

Regards,
=IceBurn=

=IceBurn=
Light Poster
25 posts since Dec 2008
Reputation Points: 18
Solved Threads: 0
 

Well, what's the owner of the directory you're trying to write to, and what are its permissions? I suppose you could just set the directory's permissions to 777 and that should pretty well take care of any permission issues with regards to creating new files.

However, it's worth pointing out that files/directories set to 777 are readable, writable, and executable by all users on the system, so if that's a concern, you might want to consider changing the owner of the directory to the one that apache is set to run as and setting it to 755, which will ensure that only apache can write to the directory.

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

Hi!

Thank you all for your replies.

I end up using SuPHP and it worked just fine for what I wanted.

Thanks.

=IceBurn=
Light Poster
25 posts since Dec 2008
Reputation Points: 18
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: