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 Setting Up Python On Apache2
Author
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Sat 25 Apr '15 21:02    Post subject: Help Setting Up Python On Apache2 Reply with quote

I am try to set up python on apache2 web server.
I have looked up a lot of how to's online and i can not get them to work for me with any of the ones i have tried.
can any one help me with a how to that works or maybe you can help me with the errors i keep getting every time i try and set up python.
here is the tutorial i used to set up(https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts).
and when i do every thing here i get a server 500 error for my python script. so it tell me to go to my server logs for more info so this is whats given to me from my apache2 error log
(
[Sat Apr 25 11:32:10 2015] [error] [client *.*.*.*] (13)Permission denied: exec of '/var/www/test.py' failed, referer: http://metrikcorp.com/pages/Offline-page.php

[Sat Apr 25 11:32:10 2015] [error] [client *.*.*.*] Premature end of script headers: test.py, referer: http://metrikcorp.com/pages/Offline-page.php)

so any help 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:07    Post subject: Reply with quote

In httpd.conf load
Code:

LoadModule cgid_module modules/mod_cgid.so

        <Files ~ "\.py$">
                Options Indexes ExecCGI
                AddHandler cgi-script .py
        </Files>


Test script
Code:
#!/usr/bin/python


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



Works! make sure the script has 755 permissions
Back to top
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Mon 27 Apr '15 21:02    Post subject: Reply with quote

Thanks for all the help!
try all the thnings in the two theards and still no luck. still get som errors.

[Mon Apr 27 11:59:43 2015] [error] [client *.*.*.*] (13)Permission denied: exec of '/var/www/python/metrik.py' failed, referer: http://metrikcorp.com/pages/Offline-page$
[Mon Apr 27 11:59:43 2015] [error] [client *.*.*.*] Premature end of script headers: metrik.py, referer: http://metrikcorp.com/pages/Offline-page.php
Back to top
James Blond
Moderator


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

PostPosted: Mon 27 Apr '15 23:24    Post subject: Reply with quote

Here the config from my test server without any vhost, just the main server

http://pastebin.com/ujMEVyV7
Back to top
Metrik



Joined: 27 Oct 2013
Posts: 7

PostPosted: Tue 28 Apr '15 18:58    Post subject: Reply with quote

Thanks for the reply!
Idk what i am doing wrong. I can not get it to work for me. Here is what I have maybe you can notice something.
Here is my set up. http://pastebin.com/DxFDngZd
I have installed ubuntu server 13.10 32 bit on my virtualbox.
This is the tutorial I follow on setting up my lamp https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu.

This is the errors from apache that i get.
[Tue Apr 28 09:46:21 2015] [error] [client *.*.*.*] (13)Permission denied: ex$
[Tue Apr 28 09:46:21 2015] [error] [client *.*.*.*] Premature end of script h$


I also made sure to chmod the file to 755.
I did the same for the directories that would be holding my .py files.

This is the web page (http://metrikcorp.com/python/metrik.py) and the error (Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.) I get from the web browser when I try to go to my .py file.

Thanks every one!
Back to top
glsmith
Moderator


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

PostPosted: Tue 28 Apr '15 20:52    Post subject: Reply with quote

Code:


#!/usr/bin/ python
           ^
         space


Is that space really in your code? I have a hard time believing that is valid, even on linux. I'll bet that is it.
#!/usr/bin/python

If not, try adding ScriptLog to your config. If it works like it does for Perl, any error that is output to the console (if it were running in the console) will land in the ScriptLog file.

http://httpd.apache.org/docs/2.4/mod/mod_cgi.html#scriptlog

You may also want to use
#!/usr/bin/python -d

Will give debug info hopefully to this log file.
Back to top


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