title: Run a shell command as another user or change Apache's user?
body: <p>I've been trying to figure out how to do this the whole day. </p>
  
  <p><strong>The short version:</strong> I have to manage some virtual machines using php shell_exec function, so far I cant do this because apache is run by the user www-data and virtualbox by the user vboxuser</p>
  
  <p>From what I've read so far, I've thought of 3 possible solutions: 
  1.- Create a script on my vboxuser that I can call from php to manage the Virtual Machines.
  2.- Change the apache user from www-data to vboxuser so I can manage the Virtual Machines through php
  3.- Reinstall VirtualBox, this time using www-data as my user. </p>
  
  <p>I'm not sure if any of these will work and I'm not too sure of which would be the best solution. Any suggestions/ideas? </p>
  
  <p><strong>Thanks in advance.</strong></p>
  
  <p><strong>Now the longer more detailed version:</strong></p>
  
  <p>I have a remote server running Ubuntu 10.04.2, in that server I have set up VirtualBox so I can run several instances of WinXP to perform different tasks. </p>
  
  <p>Everything is setup and I can manage the virtual machines through SSH. If I want to run them as a different user than the one that created them (a user that so far only has been used to create the Virtual Machines) I have to do sudo -u vboxuser.</p>
  
  <p>Now, I need to create a PHP script to manage these virtual machines (I know about phpVirtualBox, but it's not what I need). If I try to run the virtual machines using shell_exec() from php, I get no answer at all (And I have tested that shell_exec is working on my server).</p>