Understanding the Owner of a File Saved in PHP

Asked 2 years ago, Updated 2 years ago, 63 views

I'm running it locally on Apache on Mac Yosemite.
If you look at the running users in PHP as shown below,

 echo get_current_user();

Then it becomes "_www", but when I save the text file, the owner is "My Name".
The execution user and the owner are separate (the group is also separate), but what kind of setting is this?
By the way, the target folder's permission is 0755, and suEXEC is not enabled.Also, PHP is a modular version.

Additional
Code executed.

 echo'user: '.get_current_user().'<br>';

$file_handle=fopen("test.txt", "w");

if($file_handle){
    $wr=fwrite($file_handle, "Aye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye-ye\n);

    if($wr==FALSE){
        echo "fwrite Failed <br>";
    } else {
        echo "fwrite Success <br>";
    }

    fclose($file_handle);
} else {
    echo "fopen failed <br>";
}

The owner and group confirmation was done from Finder's Right-click - View Information.
After that, he saw httpd.conf and thought the group was different.

php macos apache

2022-09-30 20:18

2 Answers

I enabled mod_php in OS X standard apache and ran the above script in DocumentRoot /Library/WebServer/Documents, but I couldn't write it.I tried chmod777 in the directory and was able to run it.The file was owned by _www.

So at least a normal state + minimum change doesn't work like a question.

Generally speaking, in the apache+mod_php environment, the execution user of apache also runs the PHP script, so there is no contradiction in the above behavior.

Therefore, if it doesn't work as it is, I think you've done more than I wrote here, but if you don't know the details, this answer is the limit.

"Also, you should doubt things like ""just writing to an existing file repeatedly"" or ""the file that the script is writing and checking is different."""


2022-09-30 20:18

When I looked at the configuration file from the terminal, it came out like this

$cat/private/etc/apache2/httpd.conf | grep-n "_www"
181—User_wwww
182—Group_wwww


2022-09-30 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.