apache - PHP: get_current_user() vs. exec('whoami') -
short version of question:
what's difference between get_current_user(); , exec('whoami'); ?
long version of question:
- i'm on xampp localhost on mac.
- i'm using apache, building php based website in folder (let's call folderxyz) within htdocs folder (var/www in flavors of linux+apache).
- i playing around database connection, testing out pdo::errmode_exception described here: link
and got error:
file_put_contents(pdoerrors.txt): failed open stream: permission denied...
so did sleuthing around , seems fix need change chmod settings of file pdoerrors.txt 777.
however, questions else. during process realized don't understand concept of user in apache, php, , mysql.
- the php manual says
get_current_user()"gets name of owner of current php script" link - the php manual says
exec('whoami')returns "the username owns running php/httpd process" link - when use
get_current_user(),firstnamelastname, account name on mac. - when use
exec('whoami'),daemon.
so...
- what's relationship between
firstnamelastname,daemon? - what's relationship between "the owner of current php script" , "username owns running php/httpd process" ?
- who needs permission write pdoerrors.txt?
firstnamelastnameordaemon? - who needs permission write pdoerrors.txt? apache or php (or both) ?
- does concept of unix-like
rootaccount factor-in anywhere here ?
edit: updated reflect wasn't folderxyz had change chmod settings for. had change settings file pdoerrors.txt
op here: future reference, put parallel question linux platform here (with accompanying intuitive explanation of what's going on): https://stackoverflow.com/questions/31389892/why-is-the-output-www-data-in-one-case-and-root-in-another
get_current_user()(should) return owner of file,firstnamelastnamein case. there have been reported issues function inconsistent between platforms however. such, not trust output.daemonuser apache running as.- the owner of php script user owns file according operating system. can run
ls -lain directory scripts in find user , group file belongs to. - whichever user you're editing scripts needs able write it, likely,
firstnamelastname(+rw). - for folder itself, should have
+rx(execute , read)daemon, php file,+r(read). on installation of xammp, they've done setting inhtdocspublic readable,daemoncan read it, not write it. - mac has root account typically owns
htdocsorwwwdirectory. fills role of traditional unix root user.
here information on file owners/groups , process owner:
host:~$ ls -l /applications/xampp/xamppfiles/htdocs drwxr-xr-x 3 root admin 4096 2015-01-01 00:01 . drwxr-xr-x 3 root admin 4096 2015-01-01 00:01 .. -rw-r--r-- 1 firstnamelastname admin 189 2015-01-31 20:45 index.php host:~$ ps aux | grep httpd | head -n1 daemon 45204 0.0 0.1 2510176 10328 ?? s tue11am 0:01.38 /applications/xampp/xamppfiles/bin/httpd -k start -e /applications/xampp/xamppfiles/logs/error_log -dssl -dphp if wanted make file writeable daemon user, can create new folder , name owner group admin (so can use too), , give +rwx user , group, +rx public:
host:~$ cd /applications/xampp/xamppfiles/htdocs host:htdocs$ mkdir some_dir host:htdocs$ chmod 775 some_dir
Comments
Post a Comment