title: Executing Linux commands from webpage
body: <p>I have set up a very basic website on apache2 server (running on Ubuntu 18.04). The website has just one page. I used some JavaScript to add dynamic content to it, and the website contains HTML form, which sends data to MySql server -- I connected to the database with PHP. </p>
  
  <p>Based on user input, I need to execute a certain Linux terminal command (say: <code>ls -l</code>). For example, if user inputs first and last names and clicks on Submit button, the <code>ls -l</code> command will automatically execute without user doing anything in terminal. Is this possible?
  This is the HTML form I have:</p>
  
  <pre><code>&lt;form method="post"&gt;
      &lt;label&gt;Fisrt Name: &lt;input type="text" name="firstname" required&gt;&lt;/label&gt;
      &lt;label&gt;Last Name: &lt;input type="text" name="lastname" required&gt;&lt;/label&gt;
      &lt;input type="submit" name="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Edited:
  Ok so I have this PHP code right now in addition to code that connects to MySql database:</p>
  
  <pre><code>&lt;?php
      $output = shell_exec('sudo addgroup test2');
      echo "&lt;pre&gt;$output&lt;/pre&gt;;
  
      $result = exec('echo $?');
      echo "$result";
  ?&gt;
  </code></pre>
  
  <p>However, it does not add this group and <code>echo $?</code> returns 0. However, when I substitute <code>shell_exec('sudo addgroup test2');</code> with <code>shell_exec('ls -l');</code> -- it works fine. What am I doing wrong?</p>