title: apache2 & PHP: execute a command from shell_exec
body: <p>I am trying to execute a command from a Javascript file through XMLHttpRequest.</p>
  
  <p>Once I created the button (something I can do without problems), the function from the Javascript code is:</p>
  
  <pre><code>function RestartService(service)
  {
      var target = document.getElementById('page');
      var spinner = new Spinner(opts).spin(target);
  
      var data = new FormData();
      data.append('service', service);
  
      var xhReq = new XMLHttpRequest();
      xhReq.open("POST", "/rservice.php", false);
      xhReq.send(data);
      var serverResponse = xhReq.responseText;
  
      timeout = setTimeout(
          function ()
          {
              spinner.stop();
          }, 1500);
  
      return serverResponse;
  }
  </code></pre>
  
  <p>while the php file I am testing is just:</p>
  
  <pre><code>&lt;?php
  //error_reporting(E_ALL);
  $fname = "/usr/local/bin/AD33x-"
  if(isset($_POST))
  {
      $service = $_POST["service"];
      $daemon = "$fname"."$service".".sh";
  
      //if(file_exists($daemon))
      {
          shell_exec("$daemon restart &gt; /dev/null 2&gt; /dev/null &amp;");
      }
  }
  
  return "ok"
  ?&gt;
  </code></pre>
  
  <p>The function <strong>RestartService</strong> is executed because I can see the spin for 1.5 s. The problems is executing the command from the PHP file. I think this is a matter of apache2 configuration, or file permissions, because if I execute, from Linux shell, the command:</p>
  
  <p><code>php -r "echo exec('/usr/local/bin/AD33x-file.sh restart');"</code></p>
  
  <p>The file is executed correctly..</p>
  
  <p>The file permissions in <em>/usr/local/bin</em> path are set to <strong>755</strong>.
  I also checked for '<em>disable_functions</em>' tag in php.ini files from <em>/etc/php</em></p>
  
  <pre><code>apache2/php.ini:315:disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
  cli/php.ini:315:disable_functions =
  </code></pre>
  
  <p>but I don't see any 'shell_exec' there... </p>
  
  <p>Actually, this is my <em>/etc/apache2/apache2.conf</em> file (with comments and white lines removed):</p>
  
  <pre><code>Mutex file:${APACHE_LOCK_DIR} default
  PidFile ${APACHE_PID_FILE}
  Timeout 300
  KeepAlive On
  MaxKeepAliveRequests 100
  KeepAliveTimeout 5
  User ${APACHE_RUN_USER}
  Group ${APACHE_RUN_GROUP}
  HostnameLookups Off
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  IncludeOptional mods-enabled/*.load
  IncludeOptional mods-enabled/*.conf
  Include ports.conf
  &lt;Directory /&gt;
      Options FollowSymLinks
      AllowOverride None
      Require all denied
  &lt;/Directory&gt;
  &lt;Directory /usr/share&gt;
      AllowOverride None
      Require all granted
  &lt;/Directory&gt;
  &lt;Directory /var/www/html&gt;
          Options Indexes FollowSymLinks MultiViews
          AuthType Basic
          AuthUserFile "/var/www/html/current/.htpasswd"
          AuthName "Authorization Required"
          Require valid-user
          Order allow,deny
          Allow from all
  &lt;/Directory&gt;
  
  AccessFileName "/var/www/html/current/.htaccess"
  
  &lt;FilesMatch "^\.ht"&gt;
      Require all denied
  &lt;/FilesMatch&gt;
  
  LogFormat "%v:%p %h %l %u %t \"%r\" %&gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
  LogFormat "%h %l %u %t \"%r\" %&gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
  LogFormat "%h %l %u %t \"%r\" %&gt;s %O" common
  LogFormat "%{Referer}i -&gt; %U" referer
  LogFormat "%{User-agent}i" agent
  
  IncludeOptional conf-enabled/*.conf
  IncludeOptional sites-enabled/*.conf
  </code></pre>
  
  <p>Perhaps there is some detail I am missing ? 
  What is the right way to execute command from PHP and apache2 ?</p>