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:

  1. i'm on xampp localhost on mac.
  2. i'm using apache, building php based website in folder (let's call folderxyz) within htdocs folder (var/www in flavors of linux+apache).
  3. 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...

  1. what's relationship between firstnamelastname , daemon ?
  2. what's relationship between "the owner of current php script" , "username owns running php/httpd process" ?
  3. who needs permission write pdoerrors.txt? firstnamelastname or daemon ?
  4. who needs permission write pdoerrors.txt? apache or php (or both) ?
  5. does concept of unix-like root account 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

  1. get_current_user() (should) return owner of file, firstnamelastname in case. there have been reported issues function inconsistent between platforms however. such, not trust output. daemon user apache running as.
  2. the owner of php script user owns file according operating system. can run ls -la in directory scripts in find user , group file belongs to.
  3. whichever user you're editing scripts needs able write it, likely, firstnamelastname (+rw).
  4. for folder itself, should have +rx (execute , read) daemon , php file, +r (read). on installation of xammp, they've done setting in htdocs public readable, daemon can read it, not write it.
  5. mac has root account typically owns htdocs or www directory. 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

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -