tags:

views:

41

answers:

2

I'm a LAMP developer trying out Python for the first time.. I'm okay with picking up the syntax, but I can't figure out how to run it on the server! I've tried the following

  • uploading filename.py to a regular web/public directory. chmod 777, 711, 733, 773... (variations of execute)
  • putting the filename.py in cgi-bin, chmod same as above..

Typing up example.com/filename.py simply loads a textfile - nothing appears to have been compiled/parsed/etc!

(I believe python is installed, as whereis python on my server shows /usr/bin/python among several other directories)

Many words for a simple question - how do you run a python file on a CentOS server?

+2  A: 

This is a big mental shift from PHP. Python files are not simply interpreted like .php files[1]. The simplest way I have found to get up & running with Python is the Bottle framework.

I recommend you spend a short while reading http://docs.python.org/howto/webservers.html. It's very informative.

[1]: Note: there is such a thing as Python Server Pages, but it's not widely used.

Tim McNamara
in other words, you can't just load up a python file by typing in its address like http://example.com/filename.py?
ina
Tim McNamara
well, i plan to use php for formating the data for display, but having php invoke the python file when needed... manually testing if the python file works, I thought the easiest way might be to just load up the URL on browser -- but i guess that won't work without installing Bottle (?) ... how do php files invoke python files anyway?
ina
Oh, this is a different question than I thought initially. If you want the PHP interpreter to envoke a Python interpreter, I recommend having a search or asking a new question.Without knowing the detail, there are probably two ways to do this. 1) Ask the operating system to do it, 2) ask the web server to do it.1) would be a matter of getting python to a result to somewhere that PHP could find it (file/stdout)2) reference the URL of the .py file, and configure the webserver to envoke the Python interpreter
Tim McNamara
+1  A: 

you can use cgi, but that will not have great performance as it starts a new process for each request.

More efficient alternatives are to use fastcgi or wsgi

A third option is to run a mini Python webserver and proxy the requests from apache using rewrite rules

gnibbler
another n00b question - is miniPython mod_python?
ina
@ina, by mini I mean something like bottle or webpy as opposed to larger frameworks such as django or zope
gnibbler