https://wiki.archlinux.org/api.php?action=feedcontributions&user=Rbreznak&feedformat=atomArchWiki - User contributions [en]2024-03-29T14:57:30ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Apache_HTTP_Server/mod_python&diff=44448Apache HTTP Server/mod python2008-07-08T16:45:35Z<p>Rbreznak: New page: Category:Networking (English) Category:HOWTOs (English) == Introduction == Mod_python is an Apache module that embeds the [http://www.python.org Python] interpreter within the...</p>
<hr />
<div>[[Category:Networking (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
== Introduction ==<br />
Mod_python is an [[Apache]] module that embeds the [http://www.python.org Python] interpreter within the server. With mod_python you can write web-based applications in Python that will run many times faster than traditional CGI and will have access to advanced features such as ability to retain database connections and other data between hits and access to Apache internals. A more detailed description of what mod_python can do is available in this O'Reilly [http://www.onlamp.com/pub/a/python/2003/10/02/mod_python.html article].<br />
<br />
== Installation ==<br />
<br />
===Apache Module : Mod_Python===<br />
<br />
This document describes how to set up and test the Apache module Mod_Python on an Arch Linux system.<br />
<br />
====Install Package====<br />
<br />
# pacman -Sy mod_python<br />
<br />
====Configure Apache====<br />
* Add this line to <code>/etc/httpd/conf/httpd.conf</code>:<br />
LoadModule python_module /usr/lib/apache/mod_python.so<br />
<br />
* Restart Apache<br />
# sudo apachectl restart<br />
<br />
* Check to make sure that Apache loaded correctly<br />
<br />
====Test Mod_Python====<br />
* Add this block to <code>/etc/httpd/conf/httpd.conf</code>:<br />
<br />
<Directory /home/www/html> <br />
AddHandler mod_python .py<br />
PythonHandler mod_python.publisher <br />
PythonDebug On <br />
</Directory><br />
<br />
* Create a file in <code>/home/www/html/</code> called <code>mptest.py</code> and add this as contents:<br />
<br />
from mod_python import apache<br />
def handler(req):<br />
req.content_type = 'text/plain'<br />
req.send_http_header()<br />
req.write("Hello World!")<br />
return apache.OK<br />
<br />
* Restart Apache<br />
# sudo apachectl restart<br />
<br />
* Check to make sure that Apache loaded correctly<br />
<br />
* Navigate to <code>http://yoursite.com/mphandler.py/handler</code> and you should see a site that just says:<br />
Hello World!<br />
<br />
With the configuration written above, you can also point your browser to any URL ending in .py in the test directory. You can for example point your browser to <code>/foobar.py</code> and it will be handled by mptest.py.<br />
<br />
== See Also ==<br />
<ul><br />
<li>[http://gentoo-wiki.com/Apache_Modules_mod_python Gentoo Wiki Mod_Python]</li><br />
<li>[http://webpython.codepoint.net/mod_python mod_python Tutorial]</li><br />
<li>[http://www.modpython.org/ http://www.modpython.org/]</li><br />
<li>[http://www.modpython.org/live/current/doc-html/ mod_python manual]</li><br />
</ul></div>Rbreznak