title: PHP: How to detect if user is root/sudo?
body: <p>I have a command line PHP script that needs to be run with root-level permissions on Linux systems.</p>
  
  <p>On our old, old Redhat Enterprise 2 Linux distro, this code worked:</p>
  
  <pre><code>// If we are linux, make sure we're root
  if ($bIsLinux &amp;&amp; $_ENV['USER'] != 'root')
      die("This script must be run as root.\n");
  </code></pre>
  
  <p>However, we've upgraded servers and are now on a modern version of linux (Amazon Linux). Which is great, but the above no longer works. On AML, you don't actually have the root password, but you can sudo from <code>ec2-user</code>. I've even tried <code>sudo -i</code> but that doesn't change the environment variable - and thus the above code fails.</p>
  
  <p>So I need a new way to ensure root-level privileges before continuing.</p>
  
  <p>Anyone have any ideas?</p>
  
  <p>Thanks!</p>