Search code examples
phppythonapachewsgi

Running Python scripts like PHP


There are Apache 2 + mod_wsgi + Python 2.6 on server.

I would like to run scripts from Python like PHP scripts. The idea may seem silly, but I'm so accustomed (at least at first learning Python).

Example:

PHP - http://example.com/script.php

Python - http://example.com/script.py

P.S. I know about mod_rewrite and other similar tricks that can do that. But it is only a disguise, and not a direct run.

UPD: My .htaccess file. index.py works, but other python scripts get 404 error.

<Files *.py>
SetHandler wsgi-script
Options ExecCGI FollowSymLinks
</Files>
 DirectoryIndex index.py

Solution

  • That doesn't look as cool as having a wsgi app running, so I recommend that you use the flask framework which is as simple as can be a sane framework.

    Here's a link describing the install procedure on mod_wsgi.

    Later on, you might want to consider a cool framework like Django, Pyramid, Grok ...

    If you really want to use mod_wsgi like mod_php check Graham Dumpleton's great answer.