title: Unable to run Python Script from PHP and print output to browser
body: <p>I've seen a lot of other people running into a similar problem where they can't run Python scripts from PHP. I'm having the same situation, but I have tried all of the solutions that people recommended, but still no luck. I also have a fresh system install and have made my scripts as simple as possible. Regardless of what I do, shell_exec() returns NULL.</p>
  
  <p>So here is how to replicate my issue:</p>
  
  <ol>
  <li>Boot up a t2.micro EC2 server on Amazon AWS</li>
  <li>Configure it as a web server (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Tutorials.WebServerDB.CreateWebServer.html" rel="nofollow noreferrer">instructions here</a>)</li>
  <li>Upload an index.php file to /var/www/html with the following code:</li>
  </ol>
  
  <hr>
  
  <pre><code>&lt;?php 
  $command = escapeshellcmd('sudo /usr/bin/python '.__DIR__.'/script.py');
  $output = shell_exec($command);
  exit(var_dump($output));
  </code></pre>
  
  <ol start="4">
  <li>Upload a script.py file to the same directory with the following code:</li>
  </ol>
  
  <hr>
  
  <pre><code>#!/usr/bin/python
  
  print('Hello!')
  </code></pre>
  
  <ol start="5">
  <li>Go to the AWS public URL. The response you will get is "NULL"</li>
  </ol>
  
  <p>So to try to solve this issue, I also changed the user group of the .py file to "apache" and I ran chmod +x on the .py file. I confirmed that ec2-user AND apache are in the sudo group. Still no luck! So what haven't I tried? What am I missing or where can I go looking for error logs?</p>