title: Change user PHP
body: <p>I need to change the user of a PHP script at runtime. I've looked at <code>posix_setuid</code>, but it looks unsecure and requires root privaledges. What would be preferable is changing the user id of the script with the users password (something like <code>posix_setuid($username, $password)</code>), and avoiding running the script as root.</p>
  
  <p>I'm open to other methods, and the script doesn't necessarily need to be PHP. However, it is going to be called from apache.</p>
  
  <p>A good anology to the scenario would be how cPanel su's to the currently logged in user on it's file manager.</p>
  
  <p>I need to change the user because I'm creating a file manager for a multi-user setup. Currently, I have the file manager set up so that apache serves my PHP file manager as root. However, this is not reasonable, because in case of a security bug in the code, one user can edit files on the entire server.</p>
  
  <p>I'm looking for a way to SU the script to the logged in user so that in case of a security flaw, the user is only restricted to their own files.</p>