Code

Changes between Version 9 and Version 10 of DjangoOnWindowsWithIISAndSQLServer


Ignore:
Timestamp:
09/21/06 05:31:33 (8 years ago)
Author:
sfb
Comment:

Tidying it up and hopefully clarifying and simplifying some bits

Legend:

Unmodified
Added
Removed
Modified
  • DjangoOnWindowsWithIISAndSQLServer

    v9 v10  
    11== Goals == 
    22 
    3 The aim of this page is to describe getting Django to run on Windows, served by IIS and with an SQL Server backend. 
     3Getting Django to run on Windows, with pages served by IIS and a SQL Server backend. Assume Windows Server 2003, IIS 6 and SQL Server 2005 where no versions are mentioned. 
    44 
    5 Useful for people who already have such a setup (You wont find me discussing the installation of SQL Server here) and can't justify (or just don't want) Apache and PostgreSQL as well. 
    6  
    7 This may take a while. Best attempted with a mug of caffeinated beverage handy. 
    8  
    9 NB, I'm working from Windows Server 2003/IIS 6 and SQL Server 2005. 
     5Useful for people who already have such a setup and can't justify (or just don't want) Apache and PostgreSQL as well. 
    106 
    117'''''Note:''' This doesn't appear to work with Django 0.91 (the pyisapie.py handler is written to the refactored APIs in 0.92 and later) [SF]'' 
    128 
    13 NB also: The whole point of this is to keep Python running even when not serving requests, to reduce the overhead of starting Python all the time. This means that a lot of changes you make while configuring it wont take effect until you do a full IIS restart. 
     9Credit to: http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/ for the Django on Windows with Postgres/Apache guide, from which I took some parts of the django-on-windows setup. 
    1410 
    15 Note: With IIS 6, you only have to right-click on the application pool running your services and select 'recycle' for changes to take. 
     11=== Requirements === 
     12 * Windows Server 
     13 * IIS installed and working serving normal pages 
     14 * SQL Server installed and working 
    1615 
    17 Credit to: http://thinkhole.org/wp/2006/04/03/django-on-windows-howto/ for the Django on Windows with Postgres/Apache guide, from which I have grabbed some parts of the django-on-windows setup. 
    18  
    19 Steps: 
    20  
     16=== Steps === 
    2117 * Install Python 
    22  * Install Python's Windows extensions (optional) 
    23  * Install an ISAPI extension for IIS 
     18 * Install PyISAPIe - an extension for IIS 
    2419 * Install Django 
    25  * Combine Django and IIS 
     20 * Connect up Django and IIS 
    2621 * Configure Django to look at SQL Server 
    2722 * Test 
     
    2924 
    3025== Install Python == 
    31 Head to http://www.python.org/ and look at the menu on the left; in the "quick links" section is a link to the Windows installer for the latest stable version of Python. Download and run it, following the wizard steps until it is complete. 
     26A simple download and install for this bit, so open http://www.python.org/ and look for "Quick Links" -> "Windows Installer" in the menu on the left. Download and run it, following the wizard steps until it is complete. Easy bit over with, let's get Python talking to IIS. 
    3227 
    33 Phew. Easy bit over with, it gets harder from here on in. 
     28== Install PyISAPIe - an ISAPI extension for IIS == 
     29There is no installer for this, so there are quite a few steps, but they aren't very complicated. 
    3430 
    35 == Install Win32 extensions for Python (Optional) == 
    36 These are some Windows specific extensions for Python, and they are NOT required for the IIS driver later. 
    37  
    38 Visit https://sourceforge.net/projects/pywin32/ and download the Windows installer, run through it. 
    39 ( That URL looks neater, but the download link gives Error 500 at the moment. This one seems to work though: http://sourceforge.net/project/showfiles.php?group_id=78018 ) 
    40  
    41 == Install an ISAPI extension for IIS == 
    42 Lots of steps, and no installer. 
    43  
    44 This is an extension that loads the Python interpreter into memory while IIS is running, and uses it to serve requests more quickly. CGI apps need to start a new instance of the interpreter for every request, this does not have that overhead - it performs a similar service to mod_python on Apache servers. 
     31This is an IIS extension that loads the Python interpreter into memory while IIS is running, and uses it to serve requests more quickly. It avoids the overhead that CGI has of starting Python for every request, however it does mean that some files are cached in memory and you wont see changes while testing your Django site until you restart the process. With IIS 6 you have to right-click on the application pool running your services and select 'recycle' for changes to take. Previous versions of IIS might the whole IIS service to be restarted. 
    4532 
    4633Go to http://pyisapie.sourceforge.net/ and download it (look in the menu on the right, under "Links" for a download link). Unzip the archive so you can copy files out of it. 
    4734 
    48 Documentation is in the readme files, but at the time of writing the install is: 
     35I will assume you've extracted it to c:\pyisapie, and are using c:\python24 as the folder where Python is installed, but please change these where necessary for your setup. 
    4936 
    50  * Copy the PyISAPIe.dll file to your Python path, e.g. c:\python24 
    51  * Set the security permissions on the dll file so that IIS can read it. In the case of IIS/Server 2003 you need to give read permissions to the "Network Service" account 
    52  * Look in the <extracted archive>\source\PyISAPIe\Python\ folder and copy the Http folder to c:\python24\lib\site-packages (adjust, depending on where you installed Python).  '''''Note:''' the Http folder is case sensitive.  Saving in 'http' (or any other variation) will not work [SF]''. 
    53  * Open the IIS Manager from Administrative Tools, and create a new virtual directory in your website (give it permissions to execute ISAPI extensions when the wizard asks. 
    54  * Go to the properties of the folder, click on the configuration button (if it's greyed out, click 'create' first), and add a new wildcard extension (the lower box), locate the pyisapie.dll file and untick the "check file exists" box. 
    55  * IIS 6 Specific: In the IIS Manager, go to the "Web Service Extensions" section, and right click -> add new web service extension. 
    56   * Give it a name, add the pyisapie.dll fill as a required file and check the box to set the extension status to allowed. 
     37There is documentation in the readme files, but at the time of writing the install consists of: 
    5738 
    58 That's it installed. In the <extracted archive>\source\PyISAPIe\Python\examples folder is a file called Info.py. Copy this to your new virtual directory folder, and then try and view http:// your site / Info.py 
     39=== Setting up Files === 
     40 * Copy PyISAPIe.dll to c:\python24\ 
     41 * Edit the properties -> security settings on that file, add "Network Service" and tick "read" permission. (So IIS can use it). 
     42 * Go to c:\pyisapie\source\PyISAPIe\Python\ and copy the entire Http folder to c:\python24\lib\site-packages. '''''Note:''' the Http folder is case sensitive.  Saving in 'http' (or any other variation) will not work [SF]''. 
    5943 
    60 Notes: 
     44=== Setting up IIS === 
     45You don't have to create a virtual directory - you can do this with the root folder. If you do use a virtual directory, say /myfolder, then only urls starting with /myfolder will be handled by PyISAPIe. If you use the root folder, all URLs will be handled by PyISAPIe, and you risk everything else on the site being inaccessible afterwards if you're not careful.  
    6146 
    62   - You don't _have_ to create a virtual directory - you can do this with the root folder. If you do choose a virtual directory, say /myfolder, then only urls starting with /myfolder will be handled by PyISAPIe. 
     47 * Open the IIS Management Console, and create a new virtual directory, and allow executing ISAPI extensions when prompted by the wizard. 
    6348 
    64   - IIS 5.x doesn't support wildcard application maps, at least not through the configuration interface.  
    65     ''[SF] 
    66     On IIS, procedure is as follows: 
    67     - Right Click on virtual directory and choose "properties" 
    68     - Ensure "Execute Permissions" is set to "Scripts and Executables" 
    69     - Click "Configuration" (opposite "Scripts and Executables") 
    70     - On "App Mappings" tab, select "Add" 
    71     - For Executable, browse to pyisapie.dll (needs full path if you enter manually) 
    72     - For extension enter ''*'' (this will redirect all requests to pyisapi) 
    73     - ''You should probably limit the verbs allowed; I left as ''all'' since it was for internal use.'' 
    74     - OK to close all the open dialogs. 
    75     [SF]'' 
    76 It should work. If it doesn't, when you find out why please come back and explain what happened and how you fixed it. ;) 
     49==== IIS 6 ==== 
     50 * View the properties of the new folder and click on the "configuration" button (if it's greyed out, click 'create' first), then add a new wildcard extension (the lower box), locate the pyisapie.dll file and untick the "check file exists" box. 
     51 
     52 * In the IIS Manager, go to the "Web Service Extensions" section, and right click -> add new web service extension. 
     53  * Give it a name (it doesn't matter what), add the pyisapie.dll fill as a required file and check the box to set the extension status to allowed. 
     54 
     55==== IIS 5 ==== 
     56 
     57 * IIS 5.x doesn't support wildcard application maps, at least not through the configuration interface. On IIS 5, the procedure is as follows: 
     58  * Right Click on virtual directory and choose "properties" 
     59  * Ensure "Execute Permissions" is set to "Scripts and Executables" 
     60  * Click "Configuration" (opposite "Scripts and Executables") 
     61  * On "App Mappings" tab, select "Add" 
     62  * For Executable, browse to pyisapie.dll (needs full path if you enter manually) 
     63  * For extension enter ''*'' (this will redirect all requests to pyisapi) 
     64  * ''You should probably limit the verbs allowed; I left as ''all'' since it was for internal use.'' 
     65  * 'OK' to close all the open dialogs. 
     66   
     67That's it installed. In c:\pyisapie\source\PyISAPIe\Python\examples folder is a file called Info.py. Copy this to your new virtual directory folder, and then try and view http://site/Info.py to test it. It should work. If it doesn't, when you find out why, please come back and explain what happened and how you fixed it. ;) 
    7768 
    7869The PyISAPIe extension has a driver for Django as well, so that's where I will be heading, after this: 
     
    116107 
    117108=== Linking Django to PyISAPIe === 
    118 Next, you must follow the readme in the PyISAPIe examples\django folder (it explains where to copy two files - one goes into the Django install (One goes into python24\lib\site-packages\django-xyz-123.egg\core\handlers\). Then edit the isapi.py file you just copied to lib\site-packages\http\. See where it says you should change a line? If applicable, edit it for your django.settings.module settings. 
     109Next, you must follow the readme in the PyISAPIe examples\django folder (it explains where to copy two files - one goes into the Django install (One goes into python24\lib\site-packages\django-xyz-123.egg\core\handlers\). Then edit the isapi.py file you just copied to lib\site-packages\Http\. See where it says you should change a line? If applicable, edit it for your django.settings.module settings. 
    119110 
    120111=== Serving Django with IIS ===