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!

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).

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.

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=

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.

Hi!

Thank you all for your replies.

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

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.