Source

Webware / WebKit / Docs / InstallGuide.html

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.8: http://docutils.sourceforge.net/" />
<title>WebKit Install Guide</title>
<link rel="stylesheet" href="../../Docs/Doc.css" type="text/css" />
</head>
<body>
<div class="document" id="webkit-install-guide">
<h1 class="title">WebKit Install Guide</h1>

<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id19">Introduction</a></li>
<li><a class="reference internal" href="#quick-start" id="id20">Quick Start</a></li>
<li><a class="reference internal" href="#prerequisites" id="id21">Prerequisites</a><ul>
<li><a class="reference internal" href="#python" id="id22">Python</a></li>
<li><a class="reference internal" href="#web-server" id="id23">Web Server</a><ul>
<li><a class="reference internal" href="#apache" id="id24">Apache</a></li>
<li><a class="reference internal" href="#iis" id="id25">IIS</a></li>
<li><a class="reference internal" href="#aolserver" id="id26">AOLserver</a></li>
<li><a class="reference internal" href="#xitami" id="id27">Xitami</a></li>
<li><a class="reference internal" href="#other-servers" id="id28">Other Servers</a></li>
</ul>
</li>
<li><a class="reference internal" href="#webware-version" id="id29">Webware Version</a></li>
<li><a class="reference internal" href="#operating-systems" id="id30">Operating Systems</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installing-webware" id="id31">Installing Webware</a></li>
<li><a class="reference internal" href="#updating-webware" id="id32">Updating Webware</a></li>
<li><a class="reference internal" href="#architecture" id="id33">Architecture</a><ul>
<li><a class="reference internal" href="#id6" id="id34">Permissions</a></li>
<li><a class="reference internal" href="#adapters" id="id35">Adapters</a></li>
<li><a class="reference internal" href="#wsgi-based-adapters" id="id36">WSGI-based Adapters</a></li>
<li><a class="reference internal" href="#scgi-based-adapters" id="id37">SCGI-based Adapters</a></li>
<li><a class="reference internal" href="#cgi-based-adapters" id="id38">CGI-based Adapters</a><ul>
<li><a class="reference internal" href="#id10" id="id39">wkcgi</a></li>
<li><a class="reference internal" href="#python-cgi-adapter" id="id40">Python CGI Adapter</a></li>
<li><a class="reference internal" href="#mod-webkit" id="id41">mod_webkit</a><ul>
<li><a class="reference internal" href="#posix-installation" id="id42">Posix Installation</a></li>
<li><a class="reference internal" href="#windows-installation" id="id43">Windows Installation</a></li>
<li><a class="reference internal" href="#apache-configuration" id="id44">Apache Configuration</a></li>
</ul>
</li>
<li><a class="reference internal" href="#id13" id="id45">AOLServer</a></li>
<li><a class="reference internal" href="#lrwp-adapter-for-xitami" id="id46">LRWP Adapter (for Xitami)</a></li>
<li><a class="reference internal" href="#fastcgi" id="id47">FastCGI</a></li>
<li><a class="reference internal" href="#mod-python" id="id48">mod_python</a></li>
<li><a class="reference internal" href="#mod-snake" id="id49">mod_snake</a></li>
<li><a class="reference internal" href="#oneshot" id="id50">OneShot</a></li>
<li><a class="reference internal" href="#isapi" id="id51">ISAPI</a></li>
</ul>
</li>
<li><a class="reference internal" href="#renaming-adapters" id="id52">Renaming Adapters</a></li>
<li><a class="reference internal" href="#adapter-problems-not-cgi" id="id53">Adapter Problems (not CGI)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#configuration" id="id54">Configuration</a><ul>
<li><a class="reference internal" href="#sessions" id="id55">Sessions</a></li>
<li><a class="reference internal" href="#contexts" id="id56">Contexts</a></li>
<li><a class="reference internal" href="#creating-a-working-directory" id="id57">Creating a Working Directory</a></li>
</ul>
</li>
<li><a class="reference internal" href="#appserver-notes" id="id58">AppServer Notes</a><ul>
<li><a class="reference internal" href="#stopping-the-app-server" id="id59">Stopping the App Server</a></li>
<li><a class="reference internal" href="#reloading-servlets" id="id60">Reloading Servlets</a></li>
<li><a class="reference internal" href="#launching-the-appserver-at-unix-boot-up" id="id61">Launching the AppServer at Unix boot up</a><ul>
<li><a class="reference internal" href="#start-script-configuration" id="id62">Start script configuration</a></li>
<li><a class="reference internal" href="#activating-the-start-script" id="id63">Activating the start script</a></li>
</ul>
</li>
<li><a class="reference internal" href="#running-threadedappserver-as-a-windows-nt-2k-xp-service" id="id64">Running ThreadedAppServer as a Windows NT/2K/XP Service</a></li>
<li><a class="reference internal" href="#other-notes" id="id65">Other Notes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#troubleshooting" id="id66">Troubleshooting</a><ul>
<li><a class="reference internal" href="#bad-marshal-data" id="id67">Bad Marshal Data</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h1>Introduction</h1>
<p>WebKit provides an application server that runs on both Unix and
Windows as a persistent application (i.e., an application that stays
running over the span of multiple requests).</p>
<p>This install guide takes you through the installation process while
showing you what options are available and how you would use
them.  There are notes for specific operating systems and web servers
preceded with tags such as <strong>Unix</strong>, <strong>WinNT</strong>, <strong>IIS</strong>, etc.</p>
<p>WebKit is fairly easy to install, but there are some important things
to know.  You will be doing yourself a favor by reading through this
guide from top to bottom (skipping sections that don't apply to you).</p>
<p>We recommend that you get a simple configuration working first,
where you can access the examples provided with Webware.  Once you've
gotten to that point, the remaining customization of the environment
is fairly simple.</p>
<p>We use the term <em>deploy</em> to mean installing your web application/site
in a well known location for access by your users.  You first <em>develop</em>
your web application and then <em>deploy</em> it.  You will see deployment
specific notes throughout the guide since the issues for these two
situations can be different.  In a nutshell, you want convenience
during development, and security and performance during deployment.</p>
<p>You can always e-mail <a class="reference external" href="mailto:webware-discuss&#64;lists.sourceforge.net">webware-discuss&#64;lists.sourceforge.net</a> to give
feedback, discuss features and get help using WebKit.</p>
</div>
<div class="section" id="quick-start">
<h1>Quick Start</h1>
<p>If you just want to get to a working configuration fast,
install python,
unpack your Webware distribution,
and do the following
(use backslashes instead of slashes if you are using Windows):</p>
<pre class="literal-block">
$ cd path/to/Webware
$ python install.py
(enter password)
$ WebKit/AppServer
</pre>
<p>You should now be able to go to your browser and open up the URL
<tt class="docutils literal"><span class="pre">http://localhost:8080</span></tt>.
The page you see is generated by <tt class="docutils literal">WebKit/Examples/Welcome.py</tt>.</p>
<p>If the AppServer fails with the error message <tt class="docutils literal">Address already in use</tt>,
you will need to tell it to use a different port number.
Edit <tt class="docutils literal">WebKit/Configs/AppServer.config</tt>, set <tt class="docutils literal">AdapterPort</tt>
and <tt class="docutils literal">HTTPPort</tt> to unused port numbers, restart AppServer,
and alter your URL accordingly.</p>
<p>The AppServer has to be running anytime you want to access a
Webware application or example.  The last line of the instructions
above is a simple way to start the AppServer in the console window
you are working in.  (There are scripts to run it
automatically at boot up, see <a class="reference internal" href="#webkit-init-script">webkit init script</a>).</p>
</div>
<div class="section" id="prerequisites">
<h1>Prerequisites</h1>
<div class="section" id="python">
<h2>Python</h2>
<p>Webware of course requires Python. It has been tested with Python
version ranging from 2.4 to 2.7.  For older Python versions, you can
still use the Webware 1.0 branch.  If you get an error message about
the version, you're probably unwittingly running the wrong version
of Python.  Change the <tt class="docutils literal">AppServer</tt> or <tt class="docutils literal">AppServer.bat</tt> scripts,
giving the full path to the correct Python interpreter.  You can also
try running Webware with PyPy.  The AppServer should work with PyPy 1.5,
but this has not been thoroughly tested and seems to be less performant.</p>
<p>Your installation of Python must be multi-threaded.  It's not entirely
uncommon for third party web host providers to leave this disabled in
Python because they don't expect that it's needed or for compatibility
with some software.  If your Python installation is not multi-threaded
you will have to reinstall it.  If you're using a third party host
provider in this situation, you may be able to install it yourself
into your home directory via a telnet or ssh account.  See the
<a class="reference external" href="http://www.python.org/download/">Python site</a> for instructions.</p>
<p>To determine if threading is enabled, start the Python interpreter
from the command line and enter <tt class="docutils literal">import thread</tt>.  If you don't get
an exception, all is well.</p>
</div>
<div class="section" id="web-server">
<h2>Web Server</h2>
<p>Webware's built-in web server is adequate for development and casual use.
Beyond that, you will want to use Webware in concert with another web server.</p>
<p>Any web server that supports CGI should be usable with Webware.
Apache is the best supported platform, both on Posix and Windows systems.
There is some experimental support for Xitami.  For all other web servers
(IIS included) you should expect to use CGI to interface with the AppServer.</p>
<div class="section" id="apache">
<h3>Apache</h3>
<p>Apache is the best supported web server, both on Posix and Windows
systems.  The <a class="reference internal" href="#mod-webkit">mod_webkit</a> adapter is the fastest way to connect to
Webware, and is only supported for Apache.  CGI is also available to
Apache users through <a class="reference internal" href="#wkcgi">wkcgi</a>.  For Windows users compiled versions of
mod_webkit and wkcgi (named <tt class="docutils literal">wkcgi.exe</tt>) are also available.
There are also other adapter options, see <a class="reference internal" href="#adapters">Adapters</a>.</p>
<p>Most of the Webware developers use Apache.</p>
</div>
<div class="section" id="iis">
<h3>IIS</h3>
<p>Microsoft's Internet Information Server, or IIS, requires some special
configuration due to its default non-standard CGI behavior.  You have
to do two things:</p>
<p>For IIS 4.0 to 6.0, configure it to handle PATH_INFO and PATH_TRANSLATED
according to the CGI specification, by running the following command:</p>
<pre class="literal-block">
&gt; cscript adsutil.vbs SET W3SVC/1/AllowPathInfoForScriptMappings 1
</pre>
<p>This is lightly documented in
<a class="reference external" href="http://msdn.microsoft.com/en-us/library/ms525840.aspx">http://msdn.microsoft.com/en-us/library/ms525840.aspx</a></p>
<p>A <a class="reference internal" href="#cgi-adapter">CGI adapter</a>, written in C, is available in
<tt class="docutils literal">WebKit/Adapters/wkcgi/wkcgi.exe</tt>.  The standard <a class="reference internal" href="#python-cgi-adapter">Python CGI adapter</a>
also works, but you must either configure IIS to run Python CGI scripts,
or you must use PyInstaller or some other program to create an
executable from the Python script.</p>
<p>In order to convert WebKit.cgi into WebKit.exe using PyInstaller,
you first have to rename it to WebKit.py, and add <tt class="docutils literal">import socket</tt>
to the top of the file (you could use a configuration file
instead, but this is easier).  After creating the <tt class="docutils literal">.exe</tt> file, delete
<tt class="docutils literal">WebKit.pyc</tt> and rename <tt class="docutils literal">WebKit.py</tt> to <tt class="docutils literal">_WebKit.py</tt>.  This will
avoid conflicts with <tt class="docutils literal">WebKit.exe</tt>.</p>
<p>There is also an ISAPI module for Webware in <tt class="docutils literal">WebKit/Adapters/wkISAPI</tt>
that needs to be compiled before use.  However, there have been
problems with memory leaks in this adapter.</p>
</div>
<div class="section" id="aolserver">
<h3>AOLserver</h3>
<p>The <a class="reference external" href="http://pywx.idyll.org">PyWX</a> project aims to meld Python and AOLserver and as part of
that, they created an AOLserver &quot;stay resident&quot; WebKit adapter for
tighter integration.  If you find that this adapter does not work
with the latest release of Webware, please notify the PyWX project.</p>
</div>
<div class="section" id="xitami">
<h3>Xitami</h3>
<p>The <a class="reference external" href="http://www.xitami.com">Xitami</a> web server purports to be smaller, and potentially easier
to install than some of the other web servers.  It can run the CGI
adapters, but for more speed the <a class="reference internal" href="#lrwp-adapter">LRWP adapter</a> uses a persistent
process for greater performance.</p>
</div>
<div class="section" id="other-servers">
<h3>Other Servers</h3>
<p>Other servers should work using a <a class="reference internal" href="#cgi-adapter">CGI adapter</a> or the <a class="reference internal" href="#scgi-connector">SCGI connector</a>.</p>
</div>
</div>
<div class="section" id="webware-version">
<h2>Webware Version</h2>
<p>Unless you just downloaded Webware (and therefore WebKit), you should
check to see if you have the latest version.  This is:</p>
<p>Webware for Python</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.1</td>
</tr>
<tr class="field"><th class="field-name">Released:</th><td class="field-body">08/03/11</td>
</tr>
</tbody>
</table>
<p>You can check for the latest version at <a class="reference external" href="http://www.webwareforpython.org">http://www.webwareforpython.org</a>.</p>
<p>If you're feeling adventurous, you can get the latest in-development
source code from the public repository.  Instructions are located at
the <a class="reference external" href="http://www.webwareforpython.org/Wiki/subversionrepositoryaccess">Webware SVN page</a>.  You can find more information about SVN in
general in the <a class="reference external" href="http://svnbook.red-bean.com">Subversion Book</a>.  The SVN version of Webware is
generally fairly stable.</p>
</div>
<div class="section" id="operating-systems">
<h2>Operating Systems</h2>
<p>WebKit actively supports Posix (Linux, BSD, Mac OS X, Solaris, etc)
and Windows (95/98/NT/2K/XP), and their various flavors.</p>
<p>Note that you don't have to develop and deploy on the same
platform.  One of the WebKit developers develops everything on Windows
98 2nd edition and deploys his web sites on BSD.  Some of the web
server setup is different, but in most cases the application itself
will require no porting (unless you specifically use non-portable
Python code in your application).</p>
<p>What follows are some OS specific notes:</p>
<dl class="docutils">
<dt>Posix/Unix:</dt>
<dd>Nothing special to report.  Both Linux and BSD have been used
with WebKit.</dd>
<dt>Windows 9x:</dt>
<dd>Although a lot of the development of both WebKit and various web
sites that use it has been done on Windows 9x, we don't recommend
that you use this operating system to actually serve your users.
Unix and NT are generally more robust and secure and therefore, more
appropriate for deployment.</dd>
<dt>Windows:</dt>
<dd><p class="first">Some Windows users are surprised that URLs passed to WebKit are case
sensitive.  While it's true that the various Windows file systems are
case insensitive, the data structures that WebKit uses internally
are not.</p>
<p>When editing path names in configuration files, keep in mind that
you are editing a Python dictionary populated with Python
strings.  Therefore your paths must either use double backslashes
(\) (since the backslash is a special character), use forward
slashes or use &quot;r-strings&quot;.  An example of a bad string is
<tt class="docutils literal"><span class="pre">'C:\All\Web\'</span></tt>.  Good examples include:</p>
<ul class="simple">
<li><tt class="docutils literal">'/All/Web'</tt></li>
<li><tt class="docutils literal"><span class="pre">'C:/All/Web'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'C:\\All\\Web'</span></tt></li>
<li><tt class="docutils literal"><span class="pre">'C:\All\Web'</span></tt></li>
</ul>
<p class="last">It's generally recommended to simply use forward slashes (/) for all
your file paths.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="installing-webware">
<h1>Installing Webware</h1>
<p>Webware's main directory contains an <tt class="docutils literal">install.py</tt> script that
should always be run first.</p>
<p>Note that the install program doesn't actually copy the Webware files
to any separate directory.  It copies files within the Webware
directory tree, modifies permissions, generates documentation, etc.</p>
<p>Also, you can run the install program as many times as you like with
no ill effect, so if you're not sure whether or not it has been run,
feel free to do so again.  If you're debugging a problem with the
installation, you can run <tt class="docutils literal">install.py <span class="pre">-v</span></tt> for verbose output.</p>
</div>
<div class="section" id="updating-webware">
<h1>Updating Webware</h1>
<p>When updating to a new major or minor version of Webware, check whether
the Webware release notes recommend updating or recreating the working
directories of your Webware applications.</p>
</div>
<div class="section" id="architecture">
<h1>Architecture</h1>
<p>The WebKit architecture involves three main entities at the top level:</p>
<ul class="simple">
<li>The web browser</li>
<li>The web server</li>
<li>The app server</li>
</ul>
<p>The browser will be something like Microsoft Internet Explorer or
Mozilla.  The web server will be something like Apache or IIS.
And finally, the app server will be WebKit, i.e. a Python process
running the WebKit modules and your custom servlets.</p>
<img alt="Architecture.gif" class="align-center" src="Architecture.gif" />
<p>The chronological order of events goes from top to bottom and then
back up to top.  In other words, the browser makes a request to the web
server which in turn makes a request to the app server.  The response
then goes from the app server to the web server to the browser.</p>
<p>For development and casual use, you can replace Apache with
the WebKit built-in web server that can be activated with the
<tt class="docutils literal">AppServer.config</tt> setting <tt class="docutils literal">EnableHTTP</tt>.  The port can be specified
with the setting <tt class="docutils literal">HTTPPort</tt> and will be <tt class="docutils literal">8080</tt> by default.</p>
<p>If you are not using the built-in web server, you will have to
get your web server and app server talking to each other.
For this purpose, you must use a WebKit <a class="reference internal" href="#adapter">adapter</a>.  You must also
activate the WebKit app server listener for adapters with the
<tt class="docutils literal">AppServer.config</tt> setting <tt class="docutils literal">EnableAdapter</tt>.  The port can be specified
with the setting <tt class="docutils literal">AdapterPort</tt> and will be <tt class="docutils literal">8086</tt> by default.
You can use several app servers listenting on different ports.</p>
<div class="section" id="id6">
<span id="permissions"></span><h2>Permissions</h2>
<p>Webware runs as whatever user you run the AppServer as.  So, while
Apache might be running as nobody, if you start the AppServer as
root then your application will be run as root.  You may wish to set
up another user specifically for running the AppServer.  On Unix:</p>
<pre class="literal-block">
$ adduser --no-create-home --system webkit
$ cd path/to/Webware/WebKit
$ sudo -u webkit ./AppServer
</pre>
<p>Whatever user you run the AppServer as, there are some directories
under Webware/WebKit/ that must be writable by that user:</p>
<ul class="simple">
<li>Cache</li>
<li>ErrorMsgs</li>
<li>Logs</li>
<li>Sessions</li>
</ul>
<p>The easiest way to do this is to make these directories writeable by
all (on Unix, that would be <tt class="docutils literal">cd Webware/WebKit; chmod <span class="pre">-R</span> a+rwX
Cache ErrorMsgs Logs Sessions</tt>).</p>
<p>You may wish to set it up this way at first, and review the
permissions and create a new user later.</p>
</div>
<div class="section" id="adapters">
<span id="adapter"></span><h2>Adapters</h2>
<p>A WebKit adapter takes an HTTP request from a web server and, as
quickly as possible, packs it up and ships it to the app server which
subsequently sends the response back to the adapter for delivery to
the web server and ultimately the web client.  More concisely, an
adapter is the go-between of the web server and the app server.</p>
<p>There are several adapters for Webware.  However, it is <strong>highly</strong>
recommended that you either use <a class="reference internal" href="#wkcgi">wkcgi</a> or <a class="reference internal" href="#mod-webkit">mod_webkit</a>.  Mod_webkit is
the fastest adapter, but requires you to use Apache and usually to
have root access to the computer.  The wkcgi program uses CGI, and so
is easy to install.  Because it's small and written in C, wkcgi is
still very fast.</p>
<p>All the adapters:</p>
<ul class="simple">
<li><a class="reference internal" href="#wkcgi">wkcgi</a> (C-based CGI script)</li>
<li><a class="reference internal" href="#mod-webkit">mod_webkit</a> (fastest!)</li>
<li><a class="reference internal" href="#mod-scgi">mod_scgi</a> (equally fast, not included with Webware)</li>
<li><a class="reference internal" href="#mod-wsgi">mod_wsgi</a> (with the WSGIAdapter)</li>
<li><a class="reference internal" href="#id12">AOLServer</a></li>
<li><a class="reference internal" href="#lrwp">LRWP</a> (Xitami)</li>
</ul>
<p>These adapters are not really recommended:</p>
<ul class="simple">
<li><a class="reference internal" href="#python-cgi-adapter">Python CGI Adapter</a></li>
<li><a class="reference internal" href="#fastcgi">FastCGI</a></li>
<li><a class="reference internal" href="#mod-python">mod_python</a> (with the ModPythonAdapter)</li>
<li><a class="reference internal" href="#mod-snake">mod_snake</a> (with the ModSnakeAdapter)</li>
<li><a class="reference internal" href="#isapi">ISAPI</a> (<em>alpha</em>, for IIS)</li>
<li><a class="reference internal" href="#oneshot">OneShot</a> (unusual to use, sometimes buggy)</li>
</ul>
</div>
<div class="section" id="wsgi-based-adapters">
<span id="wsgi-adapter"></span><span id="mod-wsgi"></span><h2>WSGI-based Adapters</h2>
<p>WSGI is a standard interface between web servers and Python web applications
that is described <a class="reference external" href="http://www.python.org/dev/peps/pep-0333/">PEP333</a>.  It was invented much later than Webware and uses
a very different approach from Webware and its WebKit architecture.  Since it
has been widely adapted as a Python standard in the last years, Webware now
comes with an adapter that serves as an interface between any WSGI compliant
webserver and the Webware application server.  For Apache, the <a class="reference external" href="http://code.google.com/p/modwsgi/">mod_wsgi</a>
module by Graham Dumpleton provides such an WSGI compliant interface.  If the
module is properly configured, this can be a solution nearly as fast as using
the native <a class="reference internal" href="#mod-webkit">mod_webkit</a> adapter.  Please see the documentation of mod_wsgi for
details.  You can use <tt class="docutils literal">WebKit/Adapters/WSGIAdapter.py</tt> as the so called WSGI
application script file for mod_wsgi.</p>
</div>
<div class="section" id="scgi-based-adapters">
<span id="scgi-connector"></span><span id="mod-scgi"></span><h2>SCGI-based Adapters</h2>
<p>Instead of using the standard WebKit adapter, you can also use any
<a class="reference external" href="http://www.mems-exchange.org/software/scgi/">SCGI</a> adapter such as mod_scgi (not part of Webware for Python).
You can activate the SCGI connector, i.e. an WebKit app server listener
for SCGI connections, with the <tt class="docutils literal">AppServer.config</tt> setting <tt class="docutils literal">EnableSCGI</tt>.
The port can be specified with the setting <tt class="docutils literal">SCGIPort</tt> and will be <tt class="docutils literal">8084</tt>
by default (SCGI often uses port 4000 or 9999, you may want to change that).
The SCGI connector is actually very similar to the original Webware connector,
but since Webware predates the SCGI protocol, it was added only later as an
alternative that has not been in wide use. However, with mod_scgi, it is one
of the fastest solutions for serving Webware applications.</p>
</div>
<div class="section" id="cgi-based-adapters">
<span id="cgi-adapter"></span><h2>CGI-based Adapters</h2>
<p>CGI-based adapters are the easiest to set up, and outside of Apache,
Xitami, and AOLServer they are pretty much the only option.</p>
<p>Though these are CGI-based adapters, WebKit still runs as a persistent
program with the AppServer.  The CGI adapter is a program executed by
the web server, which then contacts the AppServer and returns the
response to the web server.  Then the adapter quits, to be started
again for another request.  This starting up and stopping is what
makes CGI slow.  Because the adapter is small, this should still be
faster than a all-CGI application, because most of the work is done in
the persistent AppServer.</p>
<div class="section" id="id10">
<span id="wkcgi"></span><h3>wkcgi</h3>
<p>wkcgi is a CGI-based adapter written in C.  It's very small and is
good at its one and only job of connecting to the AppServer.  While a
CGI-based adapter is the only option for some configurations, wkcgi is
not a bad compromise -- it's quite fast.  The only other adapter that
is enough faster to be interesting is <a class="reference internal" href="#mod-webkit">mod_webkit</a>.  You should choose
one of these options.</p>
<p>On Windows systems you should find a file
<tt class="docutils literal">WebKit/Adapters/wkcgi/wkcgi.exe</tt>.  You'll need to build the
executable yourself on Posix systems -- just do:</p>
<pre class="literal-block">
$ cd /path/to/Webware/WebKit/Adapters/wkcgi
$ make
</pre>
<p>There will be a file <tt class="docutils literal">wkcgi</tt>.  You may want to rename it to
<tt class="docutils literal">wkcgi.cgi</tt>, since in some configurations files ending in <tt class="docutils literal">.cgi</tt>
will automatically be treated as CGI scripts.</p>
<p>To use the script, make sure you put it somewhere where CGI scripts
can be executed.  This may be in a <tt class="docutils literal"><span class="pre">cgi-bin</span></tt> directory, or in some
configurations it can be located anywhere so long as the filename ends
in <tt class="docutils literal">.cgi</tt> and it's executable.  Check your error log if you are
(quickly) getting Internal Error when you try to access the script,
and for Apache see the document <a class="reference external" href="http://httpd.apache.org/docs/2.2/howto/cgi.html">Dynamic Content with CGI</a> for
configuration help.</p>
<p>If you get an Internal Error after a couple seconds, you don't have
the AppServer running.  Start the AppServer (<tt class="docutils literal">cd WebKit;
./AppServer</tt>) and try again.</p>
<p>The AppServer may also be running on a non-standard host (i.e., not
<tt class="docutils literal">localhost</tt>) or a non-standard port (not 8086).  If this is the
case, you must put a file <tt class="docutils literal">webkit.cfg</tt> in the same directory as the
wkcgi executable.  This file looks like:</p>
<pre class="literal-block">
Host = localhost
AdapterPort = 8086
MaxConnectAttempts = 10
ConnectRetryDelay = 1
</pre>
</div>
<div class="section" id="python-cgi-adapter">
<h3>Python CGI Adapter</h3>
<p>Though it's not recommended, there is an equivalent CGI script written
in Python.  This script is substantially slower, as it requires a
Python interpreter to be started for each request.  It is located in
<tt class="docutils literal">WebKit/Adapters/WebKit.cgi</tt> -- you may wish to point the first line
(<tt class="docutils literal"><span class="pre">#!/usr/bin/env</span> python</tt>) to the actual path of the Python
interpreter (e.g., <tt class="docutils literal"><span class="pre">#!/usr/local/bin/python</span></tt>).</p>
<p>Otherwise, follow the instructions for <a class="reference internal" href="#wkcgi">wkcgi</a>.  Particularly, make sure
that the script is executable.  There is no configuration, and <tt class="docutils literal">WebKit.cgi</tt>
should be able to find the host and port of the AppServer automatically.</p>
</div>
<div class="section" id="mod-webkit">
<h3>mod_webkit</h3>
<p>This is a native Apache module designed solely to communicate with
WebKit.  It is written in C, and has been tested on Linux and Windows.
It can only be used with Apache.</p>
<p>This adapter is the fastest of the adapters available for WebKit.
It is relatively easy to install, but you probably will need administrator
or root access to the machine.</p>
<p>The source code and a README file describing how to configure, build and
install mod_webkit as a DSO module for Apache 2.2 are located in the
<tt class="docutils literal">Webware/WebKit/Adapters/mod_webkit2</tt> directory.  You can also find an
older version for Apache 1.3 in <tt class="docutils literal">Webware/WebKit/Adapters/mod_webkit1</tt>,
but in the following we are assuming you are using Apache 2.2.</p>
<div class="section" id="posix-installation">
<h4>Posix Installation</h4>
<p>To install:</p>
<pre class="literal-block">
$ cd /path/to/Webware/WebKit/Adapters/mod_webkit2
$ make
$ make install
</pre>
<p>The most common error you will get in this process is an error
<tt class="docutils literal">make: /usr/sbin/apxs: Command not found</tt>.  This means the
<tt class="docutils literal">apxs</tt> utility is probably located somewhere else, or you do not
have it installed.  It should be in one of these locations:</p>
<blockquote>
<ul class="simple">
<li>/usr/bin/apxs</li>
<li>/usr/local/bin/apxs</li>
<li>/usr/local/sbin/apxs</li>
<li>/usr/local/Apache-.../.../apxs</li>
</ul>
</blockquote>
<p>If you have an Apache directory under <tt class="docutils literal">/usr/local</tt>, you should
search it for the file.  Execute the command <tt class="docutils literal">find
<span class="pre">/usr/local/Apache...</span> <span class="pre">-name</span> apxs</tt> to search for it.</p>
<p>If you cannot find it in any of these locations there is a good chance
you don't have it installed.  You should install an apache-devel
package.</p>
<p>Once you've found or attained the apxs utility, change the
<tt class="docutils literal">Makefile</tt> file in the mod_webkit directory.  Where it says
<tt class="docutils literal"><span class="pre">APXS=/usr/sbin/apxs</span></tt>, change it to the appropriate location.</p>
<p><tt class="docutils literal">make install</tt> will copy the compiled module to the appropriate
location and add a line to your httpd.conf file to load the module
(but not activate it, see <a class="reference internal" href="#apache-configuration">Apache Configuration</a> below).</p>
</div>
<div class="section" id="windows-installation">
<h4>Windows Installation</h4>
<p>Copy <tt class="docutils literal">WebKit/Adapters/mod_webkit2/mod_webkit.dll</tt> into your Apache 2.2
module directory (usually located at
<tt class="docutils literal"><span class="pre">C:\Program</span> Files\Apache Software Foundation\Apache2.2\modules\mod_webkit.so</tt>).
You should also change the extension of the file to <tt class="docutils literal">.so</tt> according
to the Apache convention.</p>
<p>Edit <tt class="docutils literal">httpd.conf</tt> to include the line:</p>
<pre class="literal-block">
LoadModule webkit_module modules/mod_webkit.so
</pre>
<p>Then, add the configuration below to activate the module.</p>
</div>
<div class="section" id="apache-configuration">
<h4>Apache Configuration</h4>
<p>You must also add something like this to your httpd.conf:</p>
<pre class="literal-block">
&lt;Location /WK&gt;
    WKServer localhost 8086
    SetHandler webkit-handler
&lt;/Location&gt;
</pre>
<p>Some Apache 2.2 users have found that they must use &quot;127.0.0.1&quot; instead
of &quot;localhost&quot;, since Apache 2.2 defaults to using ipv6 addresses first.</p>
<p>With these lines, any URL that starts with <tt class="docutils literal">/WK/</tt> will be directed to the
AppServer on port 8086.  You can also use:</p>
<pre class="literal-block">
AddHandler psp-handler .psp
</pre>
<p>to run PSP files that are found anywhere (similar to how PHP would
work, for example).  You still need the <tt class="docutils literal">/WK</tt> portion to tell
mod_webkit where to find the AppServer.</p>
<p>To pass additional client HTTP headers through to the AppServer,
use the <tt class="docutils literal">PassHeader</tt> Apache directive.
For example:</p>
<pre class="literal-block">
PassHeader Accept-Language
</pre>
<p>Your servlet code can access the header value like this:</p>
<pre class="literal-block">
lang = self.request().environ().get('Accept-Language')
</pre>
<p>If the client request contains the header <tt class="docutils literal"><span class="pre">Accept-Language:</span> fr</tt>,
the above code will set <tt class="docutils literal">lang</tt> to <tt class="docutils literal">&quot;fr&quot;</tt>.</p>
</div>
</div>
<div class="section" id="id13">
<span id="id12"></span><h3>AOLServer</h3>
<p>This adapter comes with the Python-enhanced AOLserver created by the
<a class="reference external" href="http://pywx.idyll.org">PyWX project</a> and is described there.</p>
</div>
<div class="section" id="lrwp-adapter-for-xitami">
<span id="lrwp-adapter"></span><span id="lrwp"></span><h3>LRWP Adapter (for Xitami)</h3>
<p>The LRWP Adapter is meant to be used with the <a class="reference external" href="http://www.xitami.com">Xitami web server</a>.
It requires the LRWP Python library to be loaded.  We don't know
a great deal more than that.</p>
</div>
<div class="section" id="fastcgi">
<h3>FastCGI</h3>
<p>In most cases FastCGI will not be significantly faster than <a class="reference internal" href="#wkcgi">wkcgi</a>
(and may be slower!), and FastCGI is considerably slower than
<a class="reference internal" href="#mod-webkit">mod_webkit</a>.  At the same time it is also much more difficult to
configure.  Its use is <em>not</em> recommended.</p>
<p>Your web server will have to be FastCGI enabled, which you may be able
to accomplish by downloading software at <a class="reference external" href="http://www.FastCGI.com">http://www.FastCGI.com</a> where
you can also learn more about FastCGI.</p>
<p>The top of <tt class="docutils literal">WebKit/Adapters/FCGIAdapter.py</tt> contains a doc string
explaining its setup.</p>
<p>Note that to date, we have only gotten this to work on Unix.</p>
</div>
<div class="section" id="mod-python">
<h3>mod_python</h3>
<p>In most cases the mod_python adapter will not be significantly faster
than <a class="reference internal" href="#wkcgi">wkcgi</a> (and may be slower!), and the mod_python adapter is
considerably slower than <a class="reference internal" href="#mod-webkit">mod_webkit</a>.  At the same time it is also
much more difficult to configure.  Its use is <em>not</em> recommended.</p>
<p>The top of <tt class="docutils literal">WebKit/Adapters/ModPythonAdapter.py</tt> contains a doc
string explaining the setup.</p>
<p>This has been tested on both Unix and Windows.  On Windows you should
use mod_python 2.7.4 or later because there is a bug in earlier
versions of mod_python for Windows that can cause Apache to crash or
return incorrect responses under heavy load.</p>
<p>More information about mod_python can be found at
<a class="reference external" href="http://www.modpython.org">http://www.modpython.org</a>.</p>
</div>
<div class="section" id="mod-snake">
<h3>mod_snake</h3>
<p>In most cases the mod_snake adapter will not be significantly faster
than <a class="reference internal" href="#wkcgi">wkcgi</a> (and may be slower!), and the mod_snake adapter is
considerably slower than <a class="reference internal" href="#mod-webkit">mod_webkit</a>.  At the same time it is also
much more difficult to configure.  Its use is <em>not</em> recommended.</p>
<p>This adapter is similar to ModPython, but written for the mod_snake
Apache module.  mod_snake is another method of embedding a python
interpreter into Apache.</p>
<p>A doc string is included at the top of
<tt class="docutils literal">WebKit/Adapters/ModSnakeAdapter.py</tt> which describes the
configuration steps to use this adapter.</p>
</div>
<div class="section" id="oneshot">
<h3>OneShot</h3>
<p>The OneShot adapter is another CGI based adapter, but unlike wkcgi and
WebKit.cgi, the AppServer launches, serves a response and shuts down
for every single request via OneShot.cgi.</p>
<p>OneShot is very slow, and has caused numerous weird errors over time.
If you use OneShot and encounter a bug, <em>be sure</em> to report that
you're using OneShot when you submit the bug.  Most of the developers
don't use OneShot anymore, and it's not as well tested as other parts
of the Webware code (and the constant starting and stopping of the
AppServer is also not well tested).</p>
<p>You may want to use OneShot on a commercial host where persistent
processes (like the AppServer process) are not allowed.  However, be
warned that OneShot is <em>very</em> slow.</p>
<p>If you use OneShot, do not launch the AppServer separately.  Note that
in this case, the instructions on setting the <a class="reference internal" href="#permissions">permissions</a> apply to
the user running the web server.</p>
</div>
<div class="section" id="isapi">
<h3>ISAPI</h3>
<p>The ISAPI module is located in <tt class="docutils literal">WebKit/Adapters/wkISAPI</tt>.
It currently has some memory leaks and is not well tested.  It is
looking for a maintainer.  There's no documentation for it, and you
must compile it yourself.</p>
</div>
</div>
<div class="section" id="renaming-adapters">
<h2>Renaming Adapters</h2>
<p>Adapters such as WebKit.cgi and OneShot.cgi do not rely on their
name.  Consequently, when you deploy your web site, you can rename the
adapter to something like <tt class="docutils literal">serve.cgi</tt>.  This allows you to switch
adapters later without affecting the URLs and therefore the bookmarks
of your users (provided you're still using some form of CGI adapter).
<a class="reference external" href="http://webware.colorstudy.net/twiki/bin/view/Webware/ModRewriteRecipes">mod_rewrite</a> also offers several possibilities for changing names,
redirecting the root of a site to a specific context, or other URL
manipulations.  Mod_rewrite is extremely general.</p>
</div>
<div class="section" id="adapter-problems-not-cgi">
<h2>Adapter Problems (not CGI)</h2>
<p>There is one gotcha in setting up the adapters that don't rely on CGI.
For mod_webkit, ModPython and ModSnake, the name that you give to the
adapter location in your Apache configuration file must not actually
exist in your Apache document root.  Also, you may not have a file or
directory in your document root with the same name as one of WebKit's
contexts.  So, you can't have a directory named Examples in your
document root.</p>
</div>
</div>
<div class="section" id="configuration">
<h1>Configuration</h1>
<p>In this section, we'll briefly touch on some of the configuration
options related to installing and running WebKit.  A full reference to
these options can be found in the <a class="reference external" href="UsersGuide.html#Configuration">User's Guide</a>.</p>
<p>The settings referenced below are found in the configuration file,
<tt class="docutils literal">WebKit/Configs/Application.config</tt>.</p>
<div class="section" id="sessions">
<h2>Sessions</h2>
<p>WebKit provides a Session utility class for storing data on the server
side that relates to an individual user's session with your site.  The
<tt class="docutils literal">SessionStore</tt> setting determines where the data is stored and can currently
be set to <tt class="docutils literal">Dynamic</tt>, <tt class="docutils literal">File</tt>, <tt class="docutils literal">Memcached</tt>, <tt class="docutils literal">Memory</tt> or <tt class="docutils literal">Shelve</tt>.</p>
<p>Storing to the Dynamic session store is the fastest solution and is
the default.  This session storage method keeps the most recently used
sessions in memory, and moves older sessions to disk periodocally.
All sessions will be moved to disk when the server is stopped.
This storage mechanism works with both the persistant, long running
AppServers and <a class="reference internal" href="#oneshot">OneShot</a>.  There are two settings in
<tt class="docutils literal">Application.config</tt> relating to this Dynamic session store.
<tt class="docutils literal">MaxDynamicMemorySessions</tt> specifies the maximum number of sessions
that can be in memory at any one time.  <tt class="docutils literal">DynamicSessionTimeout</tt>
specifies after what period of time sessions will be moved from memory
to file.  (Note: this setting is unrelated to the <tt class="docutils literal">SessionTimeout</tt>
setting below.  Sessions which are moved to disk by the Dynamic
Session store are not deleted).  Alternatively to the Dynamic store,
you can try out the Shelve session store which stores the sessions
in a database file using the Python shelve module.</p>
<p>If you are using more than one AppServer for load-balancing, the
Memcached store will be interesting for you. Using the python-memcached
interface, it is able to connect to a Memcached system and store all the
session data there.  This allows user requests to be freely moved from one
AppServer to another while keeping their sessions, because they are all
connected to the same memcache.</p>
<p>Storing to files is provided mainly in support of the OneShot
adapter.  It may also prove useful in the future in support of load
balancing.  In this scenario, each individual session is stored in its
own file, loaded for every request and saved when delivering the
corresponding response.</p>
<p>All on-disk session information is located in WebKit/Sessions.</p>
<p>Also, the <tt class="docutils literal">SessionTimeout</tt> setting lets you set the number of
minutes of inactivity before a user's session becomes invalid and is
deleted.  The default is 60.  The Session Timeout value can also be
changed dynamically on a per session basis.</p>
<p><tt class="docutils literal">Activity Log</tt></p>
<p>Three options let you control:</p>
<blockquote>
<ul class="simple">
<li>Whether or not to log activity (<tt class="docutils literal">LogActivity</tt>, defaults to 0,
i.e. off)</li>
<li>The name of the file to store the log (<tt class="docutils literal">ActivityLogFilename</tt>,
defaults to <tt class="docutils literal">Logs/Activity.csv</tt>)</li>
<li>The fields to store in the log (<tt class="docutils literal">ActivityLogColumns</tt>) &lt;/ul&gt;</li>
</ul>
</blockquote>
<p>See <a class="reference external" href="UsersGuide.html#Configuration">Configuration</a> in the User's Guide for more information.</p>
<p>E-mail Errors</p>
<p><tt class="docutils literal">EmailErrors</tt>, <tt class="docutils literal">ErrorEmailServer</tt> and <tt class="docutils literal">ErrorEmailHeaders</tt> let
you configure the app server so that uncaught exceptions land in your
mailbox in real time.  You should definitely set these options when
deploying a web site.</p>
<p>See <a class="reference external" href="UsersGuide.html#Configuration">Configuration</a> in the User's Guide for more information.</p>
</div>
<div class="section" id="contexts">
<h2>Contexts</h2>
<p>WebKit divides the world into <em>contexts</em>, each of which is a directory
with its own files and servlets.  WebKit will only serve files out of
its list of known contexts.</p>
<p>Some of the contexts you will find out of the box are <tt class="docutils literal">Examples</tt>,
<tt class="docutils literal">Documentation</tt> and <tt class="docutils literal">Admin</tt>.  When viewing either an example or
admin page, you will see a sidebar that links to all the contexts.</p>
<p>Another way to look at contexts is a means for &quot;directory
partitioning&quot;.  If you have two distinct web applications (for example,
<tt class="docutils literal">PythonTutor</tt> and <tt class="docutils literal">DayTrader</tt>), you will likely put each of these
in their own context.  In this configuration, both web applications
would be served by the same appserver instance.  Note that there may
be also reasons to run multiple appserver instances for serving your
web applications.  For instance, this would allow you to start and stop
them independently, run them under different users to give them
different permissions, or partition resources like number of threads
individually among the web applications.</p>
<p>Instead of adding your own contexts you may wish to use
<a class="reference internal" href="#makeappworkdir">MakeAppWorkDir</a>, which will partition your application from the
Webware installation.</p>
<p>To add a new context, add to the <tt class="docutils literal">Contexts</tt> dictionary of
<tt class="docutils literal">Application.config</tt>.  The key is the name of the context as it
appears in the URL and the value is the path (absolute or relative to
the WebKit directory).  Often the name of the context and the name of
the directory will be the same:</p>
<pre class="literal-block">
'DayTrader': '/All/Web/Apps/DayTrader',
</pre>
<p>The URL to access DayTrader would then be something like:
<tt class="docutils literal"><span class="pre">http://localhost/WebKit.cgi/DayTrader/</span></tt></p>
<p>The special name <tt class="docutils literal">default</tt> is reserved to specify what context is
served when none is specified (as in
<tt class="docutils literal"><span class="pre">http://localhost/WebKit.cgi/</span></tt>).  Upon installation, this is the
<tt class="docutils literal">Examples</tt> context, which is convenient during development since it
provides links to all the other contexts.</p>
<p>Note that a context can contain an <tt class="docutils literal">__init__.py</tt> which will be
executed when the context is loaded at app server startup.  You can put
any kind of initialization code you deem appropriate there.</p>
</div>
<div class="section" id="creating-a-working-directory">
<span id="makeappworkdir"></span><h2>Creating a Working Directory</h2>
<p>You can create a working directory for your applications that is
separate from the Webware installation.  To do this you will use the
script <tt class="docutils literal">bin/MakeAppWorkDir.py</tt>.  You should run it like:</p>
<pre class="literal-block">
$ python Webware/bin/MakeAppWorkDir.py WorkDir
</pre>
<p>This will create a directory <em>WorkDir</em> that will contain a
directory structure for your application.  Name if after your
application, place it where it is convenient for you --
it doesn't need to be located close to the Webware installation.</p>
<p>You have a couple of options available, e.g. for chosing the name
and location of the default context or creating additional library
directories that will be added to the Python seach path.
You can see all of these options if you run <tt class="docutils literal">bin/MakeAppWorkDir.py</tt>
without any parameters.</p>
<p>When you list the created directory, you will see something like this:</p>
<pre class="literal-block">
AppServer*  Configs/       ErrorMsgs/  Lib/   MyContext/  WebKit.cgi
Cache/      error404.html  Launch.py   Logs/  Sessions/   webkit*
</pre>
<p>Here's what the files and directories are for:</p>
<dl class="docutils">
<dt><tt class="docutils literal">AppServer</tt>:</dt>
<dd>The script to start up the AppServer for this application.
Each application will have its own AppServer, and its own process.
If you are running under Windows, you will see a <tt class="docutils literal">AppServer.bat</tt>
instead and additionally, you will find a <tt class="docutils literal">AppServerService.py</tt>
script that can be used to start the AppServer as a service.</dd>
<dt><tt class="docutils literal">Cache</tt>:</dt>
<dd>A directory containing cache files.  You won't need to look in here.</dd>
<dt><tt class="docutils literal">Configs</tt>:</dt>
<dd>Configuration files for the application.  These files are copied from
<tt class="docutils literal">WebKit/Configs</tt>, but are specific to this application/AppServer.</dd>
<dt><tt class="docutils literal">error404.html</tt>:</dt>
<dd>The static HTML page to be displayed when a page is not found.  You can
remove this to display a standard error message, modify the page according
to your preferences, or use a custom error servlet instead by setting
<tt class="docutils literal">ErrorPage</tt> in the <tt class="docutils literal">Application.config</tt> file appropriately.</dd>
<dt><tt class="docutils literal">ErrorMsgs</tt>:</dt>
<dd>HTML pages for any errors that occur.  These can pile up and take up
considerable size (even just during development), so you'll want to
purge these every so often.</dd>
<dt><tt class="docutils literal">Launch.py</tt>:</dt>
<dd>Called by the <tt class="docutils literal">AppServer</tt> script to launch the AppServer.</dd>
<dt><tt class="docutils literal">Lib</tt>:</dt>
<dd>An example for an application-specific library package that can be
created with the <tt class="docutils literal"><span class="pre">-l</span></tt> option (in this case, <tt class="docutils literal"><span class="pre">-l</span> Lib</tt>).  Import
modules from this directory like <tt class="docutils literal">from Lib.SitePage import SitePage</tt>.</dd>
<dt><tt class="docutils literal">Logs</tt>:</dt>
<dd>Logs of accesses.</dd>
<dt><tt class="docutils literal">MyContext</tt>:</dt>
<dd>The directory for your default context.  This is where you put your servlets.
you can change its name and location with the <tt class="docutils literal"><span class="pre">`-c</span></tt> and <tt class="docutils literal"><span class="pre">-d</span></tt> options.
You can also change this subsequently in the <tt class="docutils literal">Application.config</tt> file
in the <tt class="docutils literal">Configs</tt> directory, where you can also configure more than one
context.  You may also want to remove the other standard contexts that come
with Webware from the config file.</dd>
<dt><tt class="docutils literal">Sessions</tt>:</dt>
<dd>Users sessions.  These should be cleaned out automatically, you won't
have to look in this directory.</dd>
<dt><tt class="docutils literal">WebKit.cgi</tt>:</dt>
<dd>A CGI script/adapter for accessing the AppServer here.  You can still use
the other adapters, but most of them don't need to be configured for the
individual applications.  I still recommend <tt class="docutils literal">mod_webkit</tt> or <tt class="docutils literal">wkcgi</tt>.</dd>
<dt><tt class="docutils literal">webkit*</tt>:</dt>
<dd>If you are running under Unix, you can use this as a start script
(see <a class="reference internal" href="#webkit-init-script">webkit init script</a>).</dd>
</dl>
</div>
</div>
<div class="section" id="appserver-notes">
<h1>AppServer Notes</h1>
<p>WebKit uses a process called an AppServer to handle requests.  The
AppServer is responsible for receiving a request from the adapter, and
then running it through the Application, and then sending the response
back to the adapter.</p>
<div class="section" id="stopping-the-app-server">
<h2>Stopping the App Server</h2>
<p>The recommended method of stopping the AppServer is through the
Application Control interface.  This is a servlet located in the Admin
context.  A username and password are required -- the username is
always <tt class="docutils literal">admin</tt>, and the password is set when you run <tt class="docutils literal">install.py</tt>.
(You can change the password through the <tt class="docutils literal">WebKit/Configs/Application.config</tt>
file).  This shutdown method is safer than doing a Control-C from a terminal,
as described below.</p>
<p>On all OSs, stopping the app server may also be accomplished by simply
going to its terminal/command window and hitting Control-C.  The app
server is designed to intercept this interruption and shut down as
gracefully as possible.  This includes saving session data to disk, if
necessary.</p>
<p>On Unix, a running appserver may be stopped from a terminal by typing
<tt class="docutils literal">./AppServer stop</tt>.</p>
<p>On Windows Control-C normally shuts the app server down <em>gracefully</em>,
where as Control-Break does not.  Keep that in mind and use Control-C,
unless the server is unresponsive to it.</p>
<p>On Unix if you don't have access to the terminal window of the app
server (perhaps because you used rlogin, telnet or ssh to remotely
access the machine), and &quot;AppServer stop&quot; doesn't work, you can use
<tt class="docutils literal">ps <span class="pre">-ax</span> | grep ThreadedAppServer</tt> to get the pid and <tt class="docutils literal">kill &lt;pid&gt;</tt> to
effect a Control-C.</p>
</div>
<div class="section" id="reloading-servlets">
<h2>Reloading Servlets</h2>
<p>As you develop your web application, you will change the code of your
various Python classes, including your servlets.  The WebKit app server
will detect a change in the timestamp of a servlet's source file and
automatically reload it for you.</p>
<p>However, reloading fails in two areas.  The first is that WebKit
doesn't check ancestor classes of servlets for modifications.
So if you modify an abstract class (for example, <tt class="docutils literal">SitePage</tt>,
<tt class="docutils literal">AccountPage</tt>, etc.), it won't be reloaded.  The second is that
WebKit can't check non-servlet classes.  So if you modify a utility
class (for example, <tt class="docutils literal">ShoppingCart</tt>, <tt class="docutils literal">Story</tt>, etc.), it won't be
reloaded.</p>
<p>While developing this will happen quite often.  There is a setting in
<tt class="docutils literal">WebKit/Configs/AppServer.config</tt> that you should turn on early in
your experimentations.</p>
<p>The line:</p>
<pre class="literal-block">
'AutoReload':      0,
</pre>
<p>in <tt class="docutils literal">AppServer.config</tt> controls a feature where the AppServer stops
and restarts itself if any loaded modules have been changed.</p>
<p>You can also deal with reloading problems by stopping the app server
(Control-C in its terminal/command window) and restarting it.
And an alternative way of reloading ancestor classes is through the
Application Control servlet, in the Admin context, which will provide
a list of all of the currently loaded modules, and allow you to reload
selected modules.  Be warned, reloading modules can cause strange
behavior, because instances of objects attached to the old class
definitions can still exist.  AutoReload is generally the best solution.</p>
</div>
<div class="section" id="launching-the-appserver-at-unix-boot-up">
<span id="webkit-init-script"></span><h2>Launching the AppServer at Unix boot up</h2>
<p>The script <tt class="docutils literal">WebKit/webkit</tt> is a Unix shell script launching WebKit
at boot time through the standard &quot;init&quot; mechanisms.</p>
<p>There are several variants of this script for various flavors of Unix
available in the folder <tt class="docutils literal">WebKit/StartScripts</tt>.  The <tt class="docutils literal">install.py</tt>
script copies the variant that it thinks is the best fit to <tt class="docutils literal">WebKit/webkit</tt>.
If the script does not fit to your system, you may want to try out other
variants or the <tt class="docutils literal">Generic</tt> script that should fit on most systems.</p>
<p>If you create a working directory using <tt class="docutils literal">bin/MakeAppWorkDir.py</tt> as
explained above, the <tt class="docutils literal">webkit</tt> start script will also be copied to the
working directory.</p>
<p>In order to start WebKit at boot time, copy this script to the system
folder that is destined for start scripts, which is usually <tt class="docutils literal">/etc/init.d/</tt>
(e.g. for SuSE or Debian Linux or Solaris) or <tt class="docutils literal">/etc/rc.d/init.d/</tt> (e.g. for
RedHat or Mandrake Linux).  Instead of copying the script, you can also make
a symbolic link refering to the script located in your working directory.
If you do this, the script will be able to determine the location of the
working directory from the symbolic link and you do not have to set the
location in the script itself.</p>
<div class="section" id="start-script-configuration">
<h3>Start script configuration</h3>
<p>At the top of the start script, you will find a configuration section where
you can change several variables that influence the start-up process.
The main configuration parameters are the following:</p>
<pre class="literal-block">
WORK_DIR      the location of your working directory

LOG_FILE      the location of the log file which records the standard
              and error output of the application server

PID_FILE      the location of the pid file which records the process id
              of the Python application server

WEBWARE_USER  the user to run the application server
</pre>
<p>For security reasons, you shouldn't use <tt class="docutils literal">root</tt> as the Webware user, but
a user with the least possible permissions, maybe even <tt class="docutils literal">nobody</tt>.
By default, the start script uses the owner of the <tt class="docutils literal">AppServer</tt> script.</p>
<p>For the log file and the pid file, you may either use the standard locations
on your system, usually something like <tt class="docutils literal">/var/log/webkit.log</tt> and
<tt class="docutils literal">/var/log/webkit.pid</tt> (use different names for different instances),
or you may store them in the working directory and its <tt class="docutils literal">Logs</tt> subdirectory.
In the first case, the files should be written as the root user, because
other users usually won't have writing permission for the standard locations.
In the second case, the files should be written as the Webware user, so
you won't need to be <tt class="docutils literal">root</tt> to restart the application server.
Therefore, the configuration section has another variable <tt class="docutils literal">LAUNCH_AS_WEBWARE</tt>
that determines whether Webware will launch as <tt class="docutils literal">root</tt> and then
(after writing the pid and log files) switch to the Webware user, or whether
Webware will immediately launch and write both files as the Webware user.</p>
<p>By default, the script will start as the Webware user and will write the files
to the working directory, so you have to unset <tt class="docutils literal">LAUNCH_AS_WEBWARE</tt> if you
want to use the standard system locations for the files instead.</p>
<p>Note that the application server maintains its own pid file, usually called
<tt class="docutils literal">appserver.pid</tt>.  You should use a different pid file for the start script,
although it actually records the same pid, i.e. the pid of Webware's Python
application server, not the pid of the wrapper script <tt class="docutils literal">AppServer</tt> which is
responsible for the AutoReload mechanism.</p>
<p>The start script also passes the variable <tt class="docutils literal">PYTHONOPTS</tt> to the <tt class="docutils literal">AppServer</tt>
script.  You can add options <tt class="docutils literal"><span class="pre">-U</span></tt> for unbuffered output (to the log file)
or <tt class="docutils literal"><span class="pre">-O</span></tt> if you want to use optimized Python files (i.e. <tt class="docutils literal">.pyo</tt> instead
of <tt class="docutils literal">.pyc</tt>).  You can also add additional Python libraries with <tt class="docutils literal">PYTHONPATH</tt>.</p>
</div>
<div class="section" id="activating-the-start-script">
<h3>Activating the start script</h3>
<p>First try whether your start script works:</p>
<pre class="literal-block">
&gt; ./webkit start
</pre>
<p>The WebKit application server should now be launched and you should see
it in the output of the <tt class="docutils literal">ps</tt> command.</p>
<p>Also try to stop WebKit by typing:</p>
<pre class="literal-block">
&gt; ./webkit stop
</pre>
<p>To activate the script for future boots, you still have to put symbolic links
to the runlevel directories in which you want to launch WebKit.
On some systems, you have to do this manually.  For example, if the start script
is <tt class="docutils literal">/etc/init.d/webkit</tt>, you would create the symbolic links like that:</p>
<pre class="literal-block">
&gt; cd /etc/rc0.d
&gt; ln -s ../init.d/webkit K75webkit
(repeat for rc1.d and rc6.d)
&gt; cd /etc/rc2.d
&gt; ln -s ../init.d/webkit S25webkit
(repeat for rc3.d, rc4.d, and rc5.d)
</pre>
<p>Some systems also provide a command line tool for this purpose, which will
depend on the flavor of Unix you are using.  For instance, you will use
<tt class="docutils literal">insserv</tt> on SuSE Linux, <tt class="docutils literal">chkconfig</tt> for RedHat (Fedora),
<tt class="docutils literal"><span class="pre">update-rc.d</span></tt> for Debian (Ubuntu) or <tt class="docutils literal"><span class="pre">rc-update</span></tt> for Gentoo.</p>
<p>Take care to launch the script after your web server and database and other
services you are using.  You can do this by using appropriate numbers for the
symbolic links or setting approriate hints for the command line tools at
the top of the script.</p>
<p>See the corresponding <tt class="docutils literal">man</tt> pages or administrator handbook of your Unix
system for the details of installing start scripts.</p>
</div>
</div>
<div class="section" id="running-threadedappserver-as-a-windows-nt-2k-xp-service">
<h2>Running ThreadedAppServer as a Windows NT/2K/XP Service</h2>
<p><tt class="docutils literal">AppServerService</tt> is a script that runs the <tt class="docutils literal">ThreadedAppServer</tt>
as a Windows NT Service.  This means it can be started and stopped
from the Control Panel or from the command line using <tt class="docutils literal">net start</tt>
and <tt class="docutils literal">net stop</tt>, and it can be configured in the Control Panel
to auto-start when the machine boots.  This is the preferred way
to deploy WebKit on a Windows NT/2K/XP platform.</p>
<p><tt class="docutils literal">AppServerService</tt> requires the Python <a class="reference external" href="http://www.python.org/windows/win32all/">win32all</a> extensions to
have been installed.</p>
<p>To see the options for installing, removing, starting, and stopping
the service, just run <tt class="docutils literal">AppServerService.py</tt> with no arguments.
Typical usage is to install the service to run under a particular
user account and startup automatically on reboot with:</p>
<pre class="literal-block">
&gt; python AppServerService.py ^
  --username mydomain\myusername ^
  --password mypassword --startup auto install
</pre>
<p>(Note: The caret (^) is the line continuation character under Windows.)</p>
<p>Then, you can start the service from the Services applet in the
Control Panel, where it will be listed as &quot;WebKit Application Server&quot;.
Or, from the command line, it can be started with either of
the following commands:</p>
<pre class="literal-block">
&gt; net start WebKit
&gt; python AppServerService.py start
</pre>
<p>The service can be stopped from the Control Panel or with:</p>
<pre class="literal-block">
&gt; net stop WebKit
&gt; python AppServerService.py stop
</pre>
<p>And finally, to uninstall the service, stop it and then run:</p>
<pre class="literal-block">
&gt; python AppServerService.py remove
</pre>
</div>
<div class="section" id="other-notes">
<h2>Other Notes</h2>
<p>See <a class="reference internal" href="#stopping-the-app-server">Stopping the App Server</a> and <a class="reference internal" href="#reloading-servlets">Reloading Servlets</a> above in
<a class="reference internal" href="#adapters">Adapters</a>.</p>
</div>
</div>
<div class="section" id="troubleshooting">
<h1>Troubleshooting</h1>
<div class="section" id="bad-marshal-data">
<h2>Bad Marshal Data</h2>
<p>The most common installation problem is a Python exception appearing
in your browser that says &quot;bad marshal data&quot;.  This is always caused by
pointing the web browser to the app server:</p>
<blockquote>
<a class="reference external" href="http://localhost:8086/WebKit.cgi/">http://localhost:8086/WebKit.cgi/</a></blockquote>
<p>But the app server hides behind a web server so the correct URL
would be:</p>
<blockquote>
<a class="reference external" href="http://localhost/WebKit.cgi/">http://localhost/WebKit.cgi/</a></blockquote>
<p>That requires that web server and app server are set up to talk to
each other.  And that's what the <a class="reference internal" href="#adapters">Adapters</a> section is all about...</p>
</div>
</div>
</div>
</body>
</html>