Author |
|
Metrik
Joined: 27 Oct 2013 Posts: 7
|
Posted: Thu 23 Apr '15 5:08 Post subject: Help Getting Python to Work On Apache2 webserver |
|
|
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
|
Posted: Thu 23 Apr '15 10:50 Post subject: |
|
|
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
|
Posted: Thu 23 Apr '15 17:55 Post subject: |
|
|
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
|
Posted: Thu 23 Apr '15 20:09 Post subject: |
|
|
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
|
Posted: Sat 25 Apr '15 2:31 Post subject: |
|
|
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
|
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 28 Apr '15 7:35 Post subject: |
|
|
Well, seeing as what day it is, you're excused |
|
Back to top |
|