logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Help Getting Python to Work On Apache2 webserver
Author
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Thu 23 Apr '15 5:08    Post subject: Help Getting Python to Work On Apache2 webserver Reply with quote

Hi,
I am try to get python to work on my web server(apache2). I have read a lot of things online and try them but could not get them to work. So any help on how to get python scripts to run on apache2(like my www directory. so if i put my test.py file in the www directory the test.py file will run as python. but not in other directory's) would be great. If you need more info on the problem please let me know.
Thanks Everyone!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Thu 23 Apr '15 10:50    Post subject: Reply with quote

in your document root
Code:

<Directory "C:/Users/james/www">
      <Files ~ "\.py$">
         Options ExecCGI
         AddHandler cgi-script .py
      </Files>
      Options Indexes FollowSymLinks
      AllowOverride None
      Require all granted
   </Directory>


make sureyou have loaded
LoadModule cgi_module modules/mod_cgi.so

my test script
Code:

#!/Python27/python.exe
import cgitb; cgitb.enable()

print "Content-Type: text/html;charset=utf-8\n"
print "Hello World!"
Back to top
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Thu 23 Apr '15 17:55    Post subject: Reply with quote

Thanks for the reply!
I now get a an error (you can see it here http://metrikcorp.com/python/metrik.py)
i am running on Linux Ubuntu server.

so i am not sure on how to check LoadModule cgi_module modules/mod_cgi.so . any advice on how to go about this?
and when i check my log files for apache2 this is what it says.'

[Thu Apr 23 08:51:50.508994 2015] [cgi:error] [pid 995] [client **.***.**.***:*****] AH01215: (8)Exec format error: exec of '/var/www/ex1.py' failed
[Thu Apr 23 08:51:50.510335 2015] [cgi:error] [pid 995] [client **.***.**.***:*****] End of script output before headers: ex1.py

this is the script i am running on that page(
#!/usr/bin/python
import cgitb; cgitb.enable()

print "Content-Type: text/html;charset=utf-8\n"
print "Hello World!"
)
Thanks For Your Help!
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Thu 23 Apr '15 20:09    Post subject: Reply with quote

There's httpd -M to see what modules are configured to be loaded.

Do perl/cgi scripts work, good indication mod_cgi is loaded.

I'm wondering, did you chmod 755 the test python script? I know on unix/linux/etc. you have to do that to perl scripts, I'd imagine this is no different.

It werks for me on Windows.
Back to top
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Sat 25 Apr '15 2:31    Post subject: Reply with quote

Thanks for all the help everyone!
Ya not sure if i changed a config file doing other stuff.
So i just delete the vm i had it on and started with a fresh go at this.
Do you know of any good step-by-step guides that can help me get python set up on my web server? or would some one be willing to show me step by step what to do That would be great.

Thanks!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 27 Apr '15 18:08    Post subject: Reply with quote

Follow up thread http://www.apachelounge.com/viewtopic.php?t=6505

Yes I was too lazy to merge the threads today.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 28 Apr '15 7:35    Post subject: Reply with quote

Well, seeing as what day it is, you're excused Very Happy
Back to top


Reply to topic   Topic: Help Getting Python to Work On Apache2 webserver View previous topic :: View next topic
Post new topic   Forum Index -> Other Software