views:

236

answers:

3

Hi I am trying to troubleshoot why I cannot get files to upload to my CentOS machine running on EC2 and think it may be a permissions problem (as I have gleamed from previous questions). How do I check what privileges my PHP installation has for writing files. The directory that I want to write files to has been created in the same folder as the PHP scripts that are trying to write the files and the rights for this folder is rwxr-xr-x. The owner of the folder is root. The owner of the PHP files trying to write the uploaded files is root also.

When the PHP file attempts to write the bytearray data that it is sent I get the following error message - file_put_contents failed to open stream: No such file or directory in ...

How should i reference the directory in which I want to save the file - absolute or relative? What else am I doing wrong?

cheers

+1  A: 

If PHP is running from the webserver, it depends on the web server's configuration.

The webserver may drop privileges to a specific user (Apache's User directive) or execute it as the owning user using suexec (or something similar).

Note that suexec will not allow you to run scripts as root and Apache warns you about setting the User directive to root; this means that any script run from Apache will run as root, which is quite dangerous.

R. Bemrose
+2  A: 

Assuming by PHP you mean web server process and assuming you're running default apache and haven't changed its defaults, I'd expect it to be apache user for CentOS.

Michael Krelin - hacker
Yes it is username apache for centOS
undefined
and `no such file or directory` obviously signifies absence of the destination directory.
Michael Krelin - hacker
A: 

Use:

<?php
$user = posix_getpwuid(posix_geteuid());

var_dump($user);
?>

To get the user details.

Assuming you have root access, once you get that, chown all the files so that they are the same user as the PHP process owner.

eg:

chown -R username /path/to/directory
bucabay