web2py setup scripts for windows

740 views
Skip to first unread message

黄祥

unread,
Sep 2, 2014, 8:28:58 PM9/2/14
to web...@googlegroups.com
dear all,

just want to share web2py setup scripts for windows (tested on windows 7 ultimate 64 bit).
hopefully it can be added on web2py/scripts in the future release.

thanks and best regards,
stifan
web2py-httpd-mod_wsgi-conf.txt
web2py setup scripts for windows.zip

Massimo Di Pierro

unread,
Sep 3, 2014, 9:29:04 AM9/3/14
to web...@googlegroups.com
Yes. I will add them. Thank you!

Niphlod

unread,
Sep 3, 2014, 11:11:29 AM9/3/14
to web...@googlegroups.com
hell no. I don't want 7-zip installed by web2py. and an old FIXED build of apache. And a FIXED version of python. Without checks.
And Apache. On Windows. 
No, No, No, No to the "setup scripts for windows" archive.
The configuration is fixed, old, and a poor duplicate of the ones we still have in automated scripts.

Massimo Di Pierro

unread,
Sep 5, 2014, 2:01:45 AM9/5/14
to web...@googlegroups.com
Is your point that we should not use these script or that we should not provide scripts for windows at all?
In the first case, what would you change? In the second case, why not?

Niphlod

unread,
Sep 5, 2014, 10:57:46 AM9/5/14
to web...@googlegroups.com
we should NOT use this script because:
- uses apache
- uses an old version of apache
- installs python with a fixed version in a fixed path
- installs a configuration file that is fixed and does not depict the same configurations we have in linux scripts

IMHO it's time to do a guide on how to use web2py with IIS and fastcgi (to substitute the old one we have in the book that is scary as hell), that from WS2008R2 onwards is pretty easy.
Having a script on windows that installs also all requirements (and up to date) is not easy because linux has package managers by default while Windows doesn't.
As most of the things, they're in the backlog of my brain and they'll come out as soon as I get some free time.

Tim Richardson

unread,
Sep 6, 2014, 6:31:31 PM9/6/14
to web...@googlegroups.com
Simonne, I wish to learn about IIS & fastcgi since I use web2py on windows servers a bit. If you put some notes and the steps, I will write it up to a draft guide.

daniel....@gmail.com

unread,
Sep 7, 2014, 6:48:48 AM9/7/14
to web...@googlegroups.com
I have notes on running web2py with IIS because nothing out there, including in recipes works. Specifically these notes are for 64 bit rather than 32 bit and using isapi_wsgi rather than fastcgi. (ISAPI is faster).
Here they are pretty much verbatim. It looks messy but is actually very simple, I have too many explanatory notes.

Install Python 2.7

  • download 2.x from https://www.python.org does not work with 3.x
  • python-2.7.8.amd64.msi (install for all users, add python.exe to path)

Install pywin32(required for isapi_wsgi)

Install isapi_wsgi

Install Web2Py

  • Download web2py src and extract to c: to get C:\web2py
  • run python web2py.py, enter pasword, and start service on port 80 at least once to generate paramters_80.py with the admin password.

Configure isapi_wsgi and IIS for Web2Py

Change MYAPP to / on the following line in the isapi_MYAPP.py file to host from root rather the virtual app MYAPP on default web site: vd = VirtualDirParameters(Name="MYAPP", to vd = VirtualDirParameters(Name="/",

import os, sys

path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
sys.path = [path]+[p for p in sys.path if not p==path]
import gluon.main
application=gluon.main.wsgibase

import isapi_wsgi
# The entry points for the ISAPI extension.
def __ExtensionFactory__():
    return isapi_wsgi.ISAPISimpleHandler(application)

if __name__=='__main__':
    # If run from the command-line, install ourselves.
    # python isapi_web2py.py install --server=Sitename 
    from isapi.install import *
    params = ISAPIParameters()
    # Setup the virtual directories - this is a list of directories our
    # extension uses - in this case only 1.
    # Each extension has a "script map" - this is the mapping of ISAPI
    # extensions.
    sm = [
        ScriptMapParams(Extension="*", Flags=0)
    ]
    vd = VirtualDirParameters(Name="MYAPP",
                              Description = "Web2Py in Python.",
                              ScriptMaps = sm,
                              ScriptMapUpdate = "replace"
                              )
    params.VirtualDirs = [vd]
    HandleCommandLine(params)

  • Execute python isapi_MYAPP.py install [--server=Sitename] to setup the isapi_wsgi handler in IIS
  • To ever remove, execute python isapi_MYAPP.py remove to remove the handler and application from IIS
  • For IIS application MYAPP hosted from default website create routes.py in C:\web2py so site can be accessed via IIS application MYAPP http://localhost/MYAPP/ but for hosting from root skip routes.py
routers = dict(
    BASE=dict(
        path_prefix='MYAPP',
    ),
)

Massimo Di Pierro

unread,
Sep 7, 2014, 11:43:50 AM9/7/14
to web...@googlegroups.com
Thanks. This should go in the book.

Niphlod

unread,
Sep 7, 2014, 2:03:57 PM9/7/14
to web...@googlegroups.com
uhm.. things are far more easier since python for visual studio came in this year with wfastcgi.py .... and it requires IIS 7.

assuming:
- python is on c:\python27\python.exe and you downloaded wfastcgi that installs itself on c:\python27\scripts
- your root is c:\inetpub\wwwroot

You download web2py and put it on wwwroot. You install the wfastcgi.py script.

You create a fastcgi app with fastcgi settings --> add application :
   -  full path c:\python27\python.exe
   - arguments c:\python27\scripts\wfastcgi.py
   - environmental variables
        - PYTHONPATH --> C:\inetpub\wwwroot
        - WSGI_HANDLER --> gluon.main.wsgibase
You create a handler with handler mappings --> add module mapping :
   - request path *
   - module fastcgimodule
   - executable c:\Python27\python.exe|C:\Python27\Scripts\wfastcgi.py

Alternatively, you can run the following script in a shell

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='c:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py']"

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py'].environmentVariables.[name='PYTHONPATH',value='C:\inetpub\wwwroot']" /commit:apphost

%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='C:\Python27\python.exe', arguments='C:\Python27\Scripts\wfastcgi.py'].environmentVariables.[name='WSGI_HANDLER',value='gluon.main.wsgibase']" /commit:apphost

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='c:\Python27\python.exe|C:\Python27\Scripts\wfastcgi.py',resourceType='Unspecified']"

To be fair, this works fine. Has still two "issues" : serves static with the fastcgi handler and requires web2py into the root (that is the "standard web2py setup"). Adding a routes.py with path_prefix and changing relative folders make it work into a subfolder.

Tim Richardson

unread,
Sep 8, 2014, 6:59:47 AM9/8/14
to web...@googlegroups.com
ye gods. One wonders if a virtual linux server is not the answer. 

Niphlod

unread,
Sep 9, 2014, 4:32:04 PM9/9/14
to web...@googlegroups.com
well, to be fair nginx config takes ~80 rows and other ~20 for uwsgi and another ~10 for putting uwsgi under upstart.
apache is ~40 lines. Are they more "flexible" ? Yep.

Let's not forget that if wfastcgi.py was "embeddable" in web2py as an adapter (but I didn't check the license), 10 clicks OR 4 lines of config for a proper supported and configured setup for web2py under IIS aren't that much. And it works also in Azure, since the baseline is usually WS2012R2.

Tim Richardson

unread,
Sep 12, 2014, 7:07:36 AM9/12/14
to web...@googlegroups.com
Hi Simone, I came across on old post of yours mentioning uswgi.
I downloaded cygwin, cloned uswgi and v 2.0 built first time in about two minutes so that was easy (this was on a 32 bit Windows Server 2003, an old machine not in use). 

But before I learn how to use it ... should I? In the earlier post (last year) you seemed enthusiastic. It seems to offer the chance of a pool of processes even on Windows (thanks to cygwin) which is what interests me... easy load balancing for moderate work loads. 

Did you go any further with it? 

Niphlod

unread,
Sep 12, 2014, 3:16:33 PM9/12/14
to web...@googlegroups.com
nope because - as often with FOSS and Windows - it never left the "experimental" status. I really think that wfastcgi.py will be the de-facto standard for python deployments under windows. As a matter of fact, it's what Azure is using to power, e.g., Django sites.

Tim Richardson

unread,
Sep 15, 2014, 10:29:08 PM9/15/14
to web...@googlegroups.com
In any case, a cygwin solution won't let me use the python win32 libraries.

Tim Richardson

unread,
Sep 23, 2014, 12:50:55 AM9/23/14
to web...@googlegroups.com
I made a new docroot folder and cloned web2py into it. 
So when the site runs for the first time, it attempts to create folders. 
There is a permission error because it can't do this. 

I looked at the permissions granted to the default docroot (inetpub/wwwroot) but it wasn't obvious to me what to do, except that a group called IIS_IUsRS seems to be relevant (although it does not get write permissions in the default folder).

Temporarily I have given "everyone" write permission, and got as far as web2py admin being denied because "unable to access password file", which is expected behaviour, I believe (since there isn't one yet).

 

Tim Richardson

unread,
Oct 21, 2014, 9:16:11 AM10/21/14
to web...@googlegroups.com
I've tried again, with a brand new IIS 8 installation. I also moved the webroot to drive C in case it was a problem with the resilient file system on the other drive. But same problem. It can not reliably save/edit files ending in .py. On the first attempt, communication error. A second attempt can result in a "file changed on disk" message and a merge changes result. Or it could mean I am left with a 0 byte file. Reloading sometimes shows the edits and sometimes the file is completely empty. I can't see any consistency. It is not a permission problem. I know that because there are no issues with editing views; I  only see this with .py files. 

Note that this inability to write .py files also stops admin from creating new apps, which is the problem I first saw. 




 

Tim Richardson

unread,
Oct 22, 2014, 7:24:35 AM10/22/14
to web...@googlegroups.com
My monologue continues ...

I found something interesting by accident. If the directory that the controller tries to write to is not under the document root of the website , then there is no problem.  It merrily writes .py files. I discovered this because I have a controller which does the same untarring that admin does when it installs a new app. I hardcoded directory paths in. I did not update these paths after copying the entire docroot to a different drive, and to my surprise the tar extraction ran without trouble. Usually it dies as soon as it encounters the first .py file. 

Niphlod

unread,
Oct 22, 2014, 8:37:03 AM10/22/14
to web...@googlegroups.com
I'll be joining this discussion as soon as I get time to install a fresh system. ATM I can't replicate your issues, but TBF I tested the creation of applications only 2008r2 and 2012 and no 2012r2 (where I did a fast check to ensure it was running like on 2012)

Tim Richardson

unread,
Oct 22, 2014, 4:18:41 PM10/22/14
to web...@googlegroups.com

If you are interested to RDP in to the server just let me know. My summary so far is that IIS appears to be doing something dynamic which causes the request thread to crash when .py files are created under its doc root. I can't get any logging of what goes wrong. No python exception is raised.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/hgfWnNeRIDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Richardson

unread,
Oct 25, 2014, 2:38:40 AM10/25/14
to web...@googlegroups.com
Ok, Simone is a legend. He found that a recent change in Microsoft's wfastcgi.py was causing the problem. He suggested a fix requiring IIS's URL rewrite module, which I have tested and it works. I've moved from apache to IIS now and I'll see how it goes over the coming week. 

Niphlod

unread,
Oct 26, 2014, 2:54:30 PM10/26/14
to web...@googlegroups.com
the beauty of R&D + trial and errors always amazes me. Many thanks you for keep trying and opening my eyes to what I sincerely didn't test in the latest revision of wfastcgi.py . I'm going to test it further and figure out the best logic to handle web2py in iis and - possibly - provide a setup script that ties all things up in a tidy way. Maybe later we can ship it into scripts/* with a proper web.config in examples/*.

To be exact, I found out that wfastcgi.py handles its own watcher thread over modified files that by default are any .config (usually used to configure IIS apps) AND *.py files. while this can be a sound default for "pull" frameworks like django or flask, it dies abruptely with "push" ones like web2py that create *.py files themselves. The url-rewrite module is needed just to handle static_version and having iis serving static files instead of letting fastcgi handle them.
Reply all
Reply to author
Forward
0 new messages