Embedding Python In Apache2 With mod_python (Debian/Ubuntu, Fedora/CentOS, Mandriva, OpenSUSE) - Page 3
5 OpenSUSE 115.1 Installing mod_pythonTo install mod_python, we simply run: yast -i apache2-mod_python To enable mod_python, open /etc/sysconfig/apache2 and add python to the APACHE_MODULES line, e.g. like this: vi /etc/sysconfig/apache2
Afterwards, run SuSEconfig and restart Apache: /etc/init.d/apache2 restart
5.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.
5.2.1 The Publisher HandlerTo enable the Publisher Handler, we create a mod_python configuration in /etc/apache2/conf.d/python.conf (this file doesn't exist so we create it). I'm using the default OpenSUSE document root /srv/www/htdocs here in the <Directory> directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.publisher: vi /etc/apache2/conf.d/python.conf
Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please do not create that 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/apache2 restart Now we create a little Python test script (e.g. /srv/www/htdocs/test.py) with pure Python code in it... vi /srv/www/htdocs/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.
5.2.2 The PSP HandlerTo enable the PSP Handler, we create a mod_python configuration in /etc/apache2/conf.d/python.conf (this file doesn't exist so we create it). I'm using the default OpenSUSE document root /srv/www/htdocs here in the <Directory> directive - adjust this to your needs. The important lines are AddHandler mod_python .py and PythonHandler mod_python.psp: vi /etc/apache2/conf.d/python.conf
Please note: if you use ISPConfig (from version 2.2.24 on) on the server, please do not create that 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/apache2 restart Now we create a little PSP test script (e.g. /srv/www/htdocs/test.psp) with HTML and Python code in it... vi /srv/www/htdocs/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.
6 Links
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com





print: 
Recent comments
18 hours 58 min ago
23 hours 22 min ago
1 day 2 hours ago
1 day 3 hours ago
1 day 7 hours ago
1 day 9 hours ago
1 day 9 hours ago
1 day 10 hours ago
1 day 10 hours ago
1 day 14 hours ago