title: Linux - create user through PHP
body: <p>I'm writing a PHP program that calls bash scripts. I'm using Linux (Centos). I'm trying to create a new user in Linux by entering username and password in the PHP page. this is the script I'm using:</p>
  
  <pre><code>egrep "^$1" /etc/passwd &gt;/dev/null
  if [ $? -eq 0 ]; then
      echo "$1 exists!"
      exit 1
  else
  
      sudo useradd -m -p $2 $1
      [ $? -eq 0 ] &amp;&amp; echo "User has been added to system!" || echo "Failed to add a user!"
  fi
  </code></pre>
  
  <p>this is how I call the script from PHP:</p>
  
  <pre><code>echo exec("/var/www/html/addUser.sh ".$username." ".$password);
  </code></pre>
  
  <p>it works when running it from terminal, but when calling the script from PHP it doesn't work. it is a matter of permissions. what should I do in order to allow the PHP (apache) to also add users?
  I've tried adding 'apache' to visudo both as user and as a group:</p>
  
  <pre><code>%apache ALL=(ALL)   NOPASSWD: ALL
   apache    ALL=(ALL)       ALL
  </code></pre>
  
  <p>it still doesn't work.
  any ideas? thanks.</p>