0

I'm using xampp installed on Ubuntu.

What I did: [edited the following line in httpd.conf] AddHandler cgi-script .cgi .pl .asp .py

My python script present in htdocs is:

#!/usr/bin/python3

import cgitb

print("Content-Type: text/html;charset=utf-8\n")
print ("Hello Python Web Browser!! This is cool!!")

Output result is: End of script output before headers: sample.py

  • 1
    Does this answer your question? [Executing a Python script in Apache2](https://stackoverflow.com/questions/9145517/executing-a-python-script-in-apache2) – writ3it Apr 16 '20 at 18:44
  • It is most likely to be a permission error. Fix it by giving execute permissions to script. Can you post the apache error.log? – MohitC Apr 16 '20 at 18:44
  • @writ3it I'm running this script in xampp not default sever. – Lasith Hettige Apr 16 '20 at 18:59
  • @MohitC [Thu Apr 16 07:23:06.157496 2020] [core:notice] [pid 19962] AH00094: Command line: '/opt/lampp/bin/httpd -E /opt/lampp/logs/error_log -D SSL -D PHP' sh: 1: python: not found – Lasith Hettige Apr 16 '20 at 19:17
  • Make sure python at `/usr/bin/python3` exists and is executable by others – MohitC Apr 16 '20 at 19:23
  • @MohitC All users can execute – Lasith Hettige Apr 16 '20 at 19:31
  • @MohitC [cgi:error] [pid 29732] [client 127.0.0.1:54276] AH01215: (13)Permission denied: exec of '/opt/lampp/htdocs/portScanner/sample.py' failed: /opt/lampp/htdocs/portScanner/sample.py, referer: http://localhost/portScanner/ – Lasith Hettige Apr 16 '20 at 19:34

1 Answers1

0

Looking at error log from comments, the file does not have correct permissions to execute. Simply do

$ sudo chmod -R 777 /opt/lampp/htdocs/portScanner

WARNING: It is really a bad idea to change permissions to 777 on a webserver, alternatively you could try changing ownership of this directory to the apache user which is usually www-data in ubuntu

$ sudo chwon -R www-data /opt/lampp/htdocs/portScanner
MohitC
  • 4,541
  • 2
  • 34
  • 55