Apache_Modules_mod_python
Main Modules
Addons & Tunnels Tips Configuring Other |
| edit |
Introduction
Mod_python is an Apache module that embeds the 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 article.
Installation
# emerge mod_python
Edit config by appending "-D PYTHON" to the APACHE2_OPTS global variable.
| File: /etc/conf.d/apache2 |
APACHE2_OPTS="-D PHP4 -D SSL -D DOC -D FTPD -D PYTHON" |
Restart apache
# /etc/init.d/apache2 restart
Testing
Add the following Apache directives
| File: /etc/apache2/modules.d/16_mod_python.conf |
<Directory /var/www/localhost/htdocs> AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On </Directory> |
Create simple "Hello World" application
| File: /var/www/localhost/htdocs/mptest.py |
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.send_http_header()
req.write("Hello World!")
return apache.OK
|
Note: Be careful when cutting and pasting from your browser, you may end up with incorrect indentation and a syntax error.
Restart apache
# /etc/init.d/apache2 restart
Open the url http://localhost/mptest.py/handler.
See Also
Browse categories > Applications > Webserver > Apache2
Browse categories > Programming languages > Python
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should be using interactive floor plans and real estate agent tools.
