How to run python script on ampps

From AMPPS Wiki
Jump to: navigation, search
  • To run Python Scripts on AMPPS server, add Shebang line in the file and place it in cgi-bin directory.
  • Here is a example of Python script to print Hello word:
  • Go to /path/to/Ampps/www/cgi-bin directory and create one file.
  • Add following Shebang line at the beginning of the file.

For Linux:




For Windows:


Note: In above line add actual path to Ampps directory instead of \path\to\Ampps.

  • Now print hello word.
print ("Content-type: text/plain\n\n")
print ("Hello world")
  • Save it, restart Apache.
  • Now access your file on browser localhost/cgi-bin/
  • You can also call your .py file in .php and execute that.
  • create one test.php in /Ampps/www folder and enter following code in it.
 $data=  exec('python C:\Ampps\www\cgi-bin\');
  echo "File Contain " .  $data;
  • Now run above file on browser, localhost/test.php