Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How do I run python cgi script on apache2 server on Ubuntu 16.04?

I am a newbie so I saw some tutorials. I have a python script as first.py

#!/usr/bin/python3 print "Content-type: text/html\n" print "Hello, world!"

I have multiple versions of python on my computer. I couldn't figure out my cgi enabled directory so I pasted this code at three places

  1. /usr/lib/cgi-bin/first.py

  2. /usr/lib/cups/cgi-bin/first.py

  3. /var/www/html/first.py

Now when I run this code in terminal it works fine but when I type

curl http://localhost/first.py

it spit out just simple text and does not execute.

I have given all the permissions to first.py

I have enabled and started the server by commands

a2enmod cgi systemctl restart apache2

Please tell how do I execute and what is going on here? Thanks in advance.

Answer*

Draft saved
Draft discarded
Cancel
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Dec 7, 2022 at 11:54

lang-py

AltStyle によって変換されたページ (->オリジナル) /