Question

I am developing an application which is having 2 servers. The first one is Web Server, where I save my PHP files and another one is File Server where I am storing all the files uploaded by the user.

I want to assign the write permission to directory at runtime so that I can upload the file and after uploading the file I need to change its permission to its previous state.

When I tried chomod(FILE_PATH, 0755). It shows me an error. Assign write permission as root. I have the administrator level credentials of File Server.

What I want is to "Grant permission 777 to the directory by logging in as root at runtime"

Kindly help if there is any code sample available. Thanks in Advance.

Was it helpful?

Solution

You do NOT want to have your server logging in as root. Let me say that again. You really do NOT want your webserver to be logged on as root. If you did that, anyone that got control of PHP could do anything at all on the server. It is seriously unadvisable.

What you want to do is change the owner of the folder to either be the webserver, or assign it into the same group so that the webserver can happily change your folder options and the like.

You can use sudo chown username somedir to change the owner. This article might also help clear up permissions for you.

Edit: Try this blog post for a fairly good broad-ranging article on linux permissions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top