Embedding Python In Apache2 With mod_python (Debian/Ubuntu, Fedora/CentOS, Mandriva, OpenSUSE) - Page 2
4 Mandriva 2008 Spring (2008.1)4.1 Installing mod_pythonBefore we can install mod_python, we must enable the main, main_updates, contrib, and contrib_updates repositories. Go to http://easyurpmi.zarb.org/ - it should give you the commands you need to run to enable these repositories. In my case, I ran urpmi.addmedia contrib ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/release with media_info/hdlist.cz urpmi.addmedia --update contrib_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/contrib/updates with media_info/hdlist.cz urpmi.addmedia main ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/release with media_info/hdlist.cz urpmi.addmedia --update main_updates ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/MandrivaLinux/official/2008.1/i586/media/main/updates with media_info/hdlist.cz to enable them. To install mod_python, we simply run: urpmi apache-mod_python
4.2 Configuring ApacheNow we must configure Apache so that it can handle Python files. There are two ways of doing so. The first (and default) one is to use the Publisher Handler. It allows you to write pure Python scripts with the extension .py that will be interpreted by Apache. The second way is the PSP Handler. PSP stands for Python Server Pages. It allows you to embed Python code directly in HTML code, similar to PHP. PSP files have the extension .psp.
4.2.1 The Publisher HandlerTo enable the Publisher Handler, we must edit the mod_python configuration which you can find in /etc/httpd/modules.d/16_mod_python.conf. This file contains many examples - we make a backup of it and create that file again from scratch. I'm using the default Mandriva document root /var/www/html here in the <Directory> directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.publisher: cp /etc/httpd/modules.d/16_mod_python.conf /etc/httpd/modules.d/16_mod_python.conf_orig
Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please leave out the <Directory ...>...</Directory> part in the above file since that would enable mod_python globally for the directory in question. In ISPConfig you can enable mod_python on a per-website basis instead which gives you more control whether a website can use mod_python or not. Restart Apache afterwards: /etc/init.d/httpd restart Now we create a little Python test script (e.g. /var/www/html/test.py) with pure Python code in it... vi /var/www/html/test.py
... and call it in a browser (e.g. http://192.168.0.100/test.py). If all goes well, it should display Test successful in your browser.
4.2.2 The PSP HandlerTo enable the PSP Handler, we must edit the mod_python configuration which you can find in /etc/httpd/modules.d/16_mod_python.conf. This file contains many examples - we make a backup of it and create that file again from scratch. I'm using the default Mandriva document root /var/www/html here in the <Directory> directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.psp: cp /etc/httpd/modules.d/16_mod_python.conf /etc/httpd/modules.d/16_mod_python.conf_orig
Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please leave out the <Directory ...>...</Directory> part in the above file since that would enable mod_python globally for the directory in question. In ISPConfig you can enable mod_python on a per-website basis instead which gives you more control whether a website can use mod_python or not. Also note that ISPConfig does not support the PSP Handler - it uses the Publisher Handler. Restart Apache afterwards: /etc/init.d/httpd restart Now we create a little PSP test script (e.g. /var/www/html/test.psp) with HTML and Python code in it... vi /var/www/html/test.psp
... and call it in a browser (e.g. http://192.168.0.100/test.psp). If all goes well, it should display Hello! in your browser.
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning




print: 

Recent comments
14 hours 10 min ago
16 hours 11 min ago
19 hours 22 min ago
21 hours 41 min ago
22 hours 51 min ago
1 day 10 min ago
1 day 4 hours ago
1 day 7 hours ago
1 day 7 hours ago
1 day 22 hours ago