How to run python script on ampps
- 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 test.py file.
- Add following Shebang line at the beginning of the file.
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/test.py
- 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.
<?php $data= exec('python C:\Ampps\www\cgi-bin\test.py'); echo "File Contain " . $data; ?>
- Now run above file on browser, localhost/test.php