title: PHP: get_current_user() vs. exec('whoami')
body: <p><em><strong>Short version of the question:</strong></em></p>
  <p>What's the difference between
  <code>get_current_user();</code> and <code>exec('whoami');</code> ?</p>
  <p><em><strong>Long version of the question:</strong></em></p>
  <ol>
  <li>I'm on a XAMPP Localhost on a Mac.</li>
  <li>I'm using Apache, building a PHP
  based website in a folder (let's call it <strong>folderxyz</strong>) within the
  htdocs folder (var/www in some flavors of Linux+Apache).</li>
  <li>I was playing around with a database connection,
  testing out PDO::ERRMODE_EXCEPTION described here: <a href="http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059" rel="nofollow noreferrer">Link</a></li>
  </ol>
  <p>And I got this error:</p>
  <blockquote>
  <p>file_put_contents(<strong>PDOErrors.txt</strong>): failed to open stream: Permission
  denied...</p>
  </blockquote>
  <p>So I did some sleuthing around and it seems that to fix this I need to change the <code>CHMOD</code> settings of file <strong>PDOErrors.txt</strong> to 777.</p>
  <p><strong>However, my questions are about something else.</strong> During this process I realized that I don't clearly understand the concept of <code>user</code> in Apache, PHP, and MySQL.</p>
  <ul>
  <li>The PHP manual says that <code>get_current_user()</code> <em>&quot;Gets the name of the owner of the current PHP script&quot;</em> <a href="http://php.net/manual/en/function.get-current-user.php" rel="nofollow noreferrer">Link</a></li>
  <li>The PHP manual says that <code>exec('whoami')</code> returns <em>&quot;the username that owns the running php/httpd process&quot;</em> <a href="http://php.net/manual/en/function.exec.php#refsect1-function.exec-examples" rel="nofollow noreferrer">Link</a></li>
  <li>When I use <code>get_current_user()</code>, I get my <code>firstnamelastname</code>, which is my account name on my Mac.</li>
  <li>When I use <code>exec('whoami')</code>, I get <code>daemon</code>.</li>
  </ul>
  <p><strong>So...</strong></p>
  <ol>
  <li>What's the relationship between <code>firstnamelastname</code> and <code>daemon</code> ?</li>
  <li>What's the relationship between the <em>&quot;the owner of the current PHP script&quot;</em> and <em>&quot;username that owns the running php/httpd process&quot;</em> ?</li>
  <li>Who needs permission to write to <strong>PDOErrors.txt</strong>? Is it <code>firstnamelastname</code> or <code>daemon</code> ?</li>
  <li>Who needs permission to write to <strong>PDOErrors.txt</strong>? Is it Apache or PHP (or both) ?</li>
  <li>Does the concept of a unix-like <code>root</code> account factor-in anywhere here ?</li>
  </ol>
  <hr />
  <p>Edit: I updated this to reflect that it wasn't the <strong>folderxyz</strong> that I had to change CHMOD settings for. I had to change the settings for the file <strong>PDOErrors.txt</strong></p>
  <hr />
  <p>OP here: for future reference, I put up a parallel question for the Linux platform here (with an accompanying intuitive explanation of what's going on): <a href="https://stackoverflow.com/questions/31389892/why-is-the-output-www-data-in-one-case-and-root-in-another">https://stackoverflow.com/questions/31389892/why-is-the-output-www-data-in-one-case-and-root-in-another</a></p>
  <p>Update: That question was deleted as it was deemed to be a duplicate of this one (although that was for the Linux platform, and instead of <code>daemon</code> I was getting <code>www-data</code> after doing <code>echo exec('whoami');</code> ).</p>
  <p>This is what I learned from asking this question in the Linux forum:</p>
  <blockquote>
  <p>the running process is different than the script. Yes, the process emerges from the script, but it's not the same thing. The script is owned by root, but the process is taken over by Apache and is run as www-data.</p>
  </blockquote>
  <hr />
  <p>Overall conclusion: What I learned from this process is that <strong>user</strong> is supposed to be the Apache <strong>daemon</strong> (Mac localhost) or <strong>www-data</strong> (Linux on an internet server) and that I should be using <code>exec('whoami')</code> to determine this, and I shouldn't care too much about <code>get_current_user()</code> (which probably should have been named <code>get_current_owner()</code>).</p>