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

7
  • 1
    Does this answer your question? Executing a Python script in Apache2 Commented Apr 16, 2020 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? Commented Apr 16, 2020 at 18:44
  • @writ3it I'm running this script in xampp not default sever. Commented Apr 16, 2020 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 Commented Apr 16, 2020 at 19:17
  • Make sure python at /usr/bin/python3 exists and is executable by others Commented Apr 16, 2020 at 19:23

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.