Tuesday, February 10, 2015

Django GeoDjango deploy on windows server 2012 R2 IIS 8

The battle is set me vs IIS on Windows Server 2012 R2!!

Battle Description:  install django 1.7.4, geodjango on IIS 8.5

Lets start with a BIG thanks to cstoker as  http://www.youtube.com/watch?v=kXbfHtAvubc  this was the best starting point to my adventure.  Please watch this video first.  Then follow along to install the remaining magic steps to get geodjango working on your windows server with IIS.

1. Install OSGeo4W

First you must INSTALL OSGeo4W  http://trac.osgeo.org/osgeo4w/  and install using custom methods to only select the "libs" gdal and co.  See GeoDjango install instructions here https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#windows 

2. Update environment variables

Then all you need to update are the environment variables .  Like here Screenshots below !

1.  WSGI_HANDLER                            django.core.wsgi.get_wsgi_application()
2. GDAL_DATA                                   C:\OSGeo4W64\share\gdal
    PROJ_LIB                                         C:\OSGeo4W64\share\proj
     PATH                                                C:\OSGeo4W64\bin


Interesting Links:

1 -  http://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-django-app/#troubleshooting-static-files
2 - http://mrtn.me/blog/2012/06/27/running-django-under-windows-with-iis-using-fcgi/
3- http://www.toptal.com/django/installing-django-on-iis-a-step-by-step-tutorial
4. https://github.com/Microsoft/PTVS/wiki/wfastcgi  (Django specific)




Here are some of my own text notes for easy copy paste:

# add fast CGI Application

# Full Path:
C:\Python27\python.exe

# Arguments appname is the root for example the first  /django_proj/django_proj
C:\inetpub\webs\appname\wfastcgi.py

# add module mapping
#request path enter * in the field
*
# Module
select fastcgi from list

#Executable
C:\Python27\python.exe|C:\inetpub\webs\appname\wfastcgi.py

#Name
Django Handler

# Click Request Restrictions
go and UN-SELECT Mapping invoke handler only if request is mapped to:

# windows 2012 server using plain jane python global install

# EnvironmentalVariables Collection Editor
# here you need to add all of these key : value pairs NOT including the space or :

KEY                                                    VALUE
DJANGO_SETTINGS_MODULE    appname.settings
PYTHONPATH                                 C:\Inetpub\wwwroot\appname_root
WSGI_HANDLER                            django.core.wsgi.get_wsgi_application()
GDAL_DATA                                   C:\OSGeo4W64\share\gdal
PROJ_LIB                                         C:\OSGeo4W64\share\proj
PATH                                                C:\OSGeo4W64\bin

Screenshots










django-admin-bootstrapped

Also if you are using bootstrap and the django-admin-bootstrapped you will need to add the font mime type to your web.config  file in the main folder.

 If you want to use the GUI click your site in IIS then click "MIME Types", then on the right click add, followed by entering File name extension to    .woff2   and the MIME type:   set too        font/x-woff2    click ok then done.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Django Handler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\inetpub\webs\utc_django\wfastcgi.py" resourceType="Unspecified" />
        </handlers>
        <httpErrors errorMode="Detailed" />
        <staticContent>
            <mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />
        </staticContent>
    </system.webServer>
</configuration>

Deploy Django Script to IIS


Now once this MOOO fuss is done you can run this script on the server to deploy my code from the local subversion repository to the live IIS inetpub directory.

BIG NOTE:  once done you NEED to REMOVE the Django Handler on the folder STATIC because after each new deploy this folder inherits the IIS Handler Mappings from the parent !!!!  Meaning your STATIC files do not work !


1 comment:

  1. https://twitter.com/spatialmounty/status/565125084286033920

    ReplyDelete