<p>I tried to follow a couple of googled up tutorials on setting up mod_python, but failed every time. Do you have a good, step-by step, rock-solid howto?</p>

<p>My dev box is OS X, production - Centos.</p>

[{'answer_id': 5129, 'author': 'Cristian', 'author_id': 680, 'author_profile': 'https://Stackoverflow.com/users/680', 'pm_score': 4, 'selected': False, 'text': '<p>There are two main ways of running Python on Apache. The simplest would be to use CGI and write normal Python scripts while the second is using a web framework like Django or Pylons.</p>\n\n<p>Using CGI is straightforward. Make sure your Apache config file has a cgi-bin set up. If not, follow their documentation (<a href="http://httpd.apache.org/docs/2.0/howto/cgi.html" rel="nofollow noreferrer">http://httpd.apache.org/docs/2.0/howto/cgi.html</a>). At that point all you need to do is place your Python scripts in the cgi-bin directory and the standard output will become the HTTP response. Refer to Python\'s documentation for further info (<a href="https://docs.python.org/library/cgi.html" rel="nofollow noreferrer">https://docs.python.org/library/cgi.html</a>).</p>\n\n<p>If you want to use a web framework you\'ll need to setup mod_python or FastCGI. These steps are dependent on which framework you want to use. Django provides clear instructions on how to setup mod_python and Django with Apache (<a href="http://www.djangoproject.com/documentation/modpython/" rel="nofollow noreferrer">http://www.djangoproject.com/documentation/modpython/</a>)</p>\n'}, {'answer_id': 5165, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 3, 'selected': False, 'text': '<p>Yes, mod_python is pretty confusing to set up.  Here\'s how I did it.</p>\n\n<p>In httpd.conf:</p>\n\n<pre><code>LoadModule python_module modules/mod_python.so\n\n&lt;Directory "/serverbase/htdocs/myapp"&gt;\n  AddHandler mod_python .py\n  PythonHandler myapp\n  PythonDebug On\n</code></pre>\n\n<p>and in your application directory:</p>\n\n<pre><code>$ /serverbase/htdocs/myapp$ ls -l\ntotal 16\n-r-xr-xr-x 1 root sys        6484 May 21 15:54 myapp.py\n</code></pre>\n\n<p>Repeat the configuration for each python program you wish to have running under mod_python.</p>\n'}, {'answer_id': 5168, 'author': 'Brian Lyttle', 'author_id': 636, 'author_profile': 'https://Stackoverflow.com/users/636', 'pm_score': 3, 'selected': False, 'text': '<p>Are you running Python on UNIX or Windows?</p>\n\n<p>An alternative to mod_python and FastCGI is mod_wsgi. You can find out more at <a href="http://code.google.com/p/modwsgi/" rel="nofollow noreferrer">modwsgi</a></p>\n\n<p>I have built and installed this on Solaris without problems. I had previously tried mod_python but ran into problems with shared libraries as part of the build. There are <a href="http://code.google.com/p/modwsgi/wiki/InstallationInstructions" rel="nofollow noreferrer">good install docs</a> available.</p>\n'}, {'answer_id': 14791003, 'author': 'tsbertalan', 'author_id': 1224886, 'author_profile': 'https://Stackoverflow.com/users/1224886', 'pm_score': 0, 'selected': False, 'text': "<p>The problem for me wasn't in Apache set up, but in understanding how mod_apache actually uses the .py files. Module-level statements (including those in a <code>if __name__=='__main__'</code> section) are <em>not</em> executed--I assumed that the stdout from running the script at the commandline would be what the server would output, but that's not how it works.</p>\n\n<p>Instead, I wrote a module-level function called <code>index()</code>, and had it return as a string the HTML of the page. It's also possible to have other module-level functions (e.g., <code>otherFunction()</code>) that can be accessed as further segments in the URI (e.g., <code>testScript/otherFunction</code> for the file <code>testScript.py</code>.)</p>\n\n<p>Obviously, this makes more sense than my original stdout conception. Better capability of actually using Python as a scripting language and not a humongous markup language.</p>\n"}]
['https://Stackoverflow.com/questions/5102', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/556/']