modpython and stuff
So since I've started learning python as stated in my last post, I decided I'd start playing with mod_python. I first started looking at mod_python after emailing rupa who I know as the author of ix.io, and sprunge.us (which are both python). After he recommended either mod_wsgi or mod_python, I went with mod_python after being totally confused with mod_wsgi installation, and I personally like how mod_python works vs. mod_wsgi, and for the beginning of this article, I'm just going to put a small tutorial for debian-server users who are newbies like me when it comes to apache.
1. install the packages
I personally installed the packages, if you choose to install from source more power to you, but with debian's apache install, installing mods from source is slightly confusing.
Now, assuming you're using debian's apache package, and have python2.5+ installed, use:
$ apt-get install libapache2-mod-python
2. load the module
Now, with debian's apache package, you need to use the following commands to load the mod_python module to apache:
$ cd /etc/apache2/mods-available
$ mv python.* ../mods-enabled
$ /etc/init.d/apache2 restart
3. make it work
Now, you need to cd /etc/apache2/sites-enabled/ and do the following:
/var/www
If you're using /var/www for your website(s), then use the following configuration in default (or in my case, 000-default (symlink to default in ../sites-available)):
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On </Directory>
Now, I used the next method I'm about to show, but I did this anyway, just in case. Does it matter if this is in default? I don't know for sure.
users
This is the method I'm using, which allows to enable it for certain users, in this example I made a file called james in sites-enabled and put the following in it:
DocumentRoot /home/USER/public_html/ AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On
4. restart!
Now, you need to restart apache with the following command:
$ /etc/init.d/apache2 restart
5. test
Now to be sure it works, create a file, testing.py in the area you enabled it for, and put the following code in it:
def index(): print "Hello world!"
If it works, you should view the file from your browser and see Hello world!
Well, this is the end of this tutorial, I can't guarantee it'll work, but it did for me, and I know I was a little irritated since I couldn't find any straight forward tutorials about this, so I figured I'd make my own for someone else who may be looking around, if something is wrong with my tutorial, or anyone wants to plug theirs or others, feel free to comment.