-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInstallGuide.html
More file actions
1022 lines (1018 loc) · 64.2 KB
/
Copy pathInstallGuide.html
File metadata and controls
1022 lines (1018 loc) · 64.2 KB
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<meta name="generator" content="Docutils 0.13.1: 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><p><a class="reference internal" href="#introduction" id="id14">Introduction</a></p></li>
<li><p><a class="reference internal" href="#quick-start" id="id15">Quick Start</a></p></li>
<li><p><a class="reference internal" href="#prerequisites" id="id16">Prerequisites</a></p>
<ul>
<li><p><a class="reference internal" href="#python" id="id17">Python</a></p></li>
<li><p><a class="reference internal" href="#web-server" id="id18">Web Server</a></p>
<ul>
<li><p><a class="reference internal" href="#apache" id="id19">Apache</a></p></li>
<li><p><a class="reference internal" href="#iis" id="id20">IIS</a></p></li>
<li><p><a class="reference internal" href="#other-servers" id="id21">Other Servers</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#webware-version" id="id22">Webware Version</a></p></li>
<li><p><a class="reference internal" href="#operating-systems" id="id23">Operating Systems</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#installing-webware" id="id24">Installing Webware</a></p></li>
<li><p><a class="reference internal" href="#updating-webware" id="id25">Updating Webware</a></p></li>
<li><p><a class="reference internal" href="#architecture" id="id26">Architecture</a></p>
<ul>
<li><p><a class="reference internal" href="#id4" id="id27">Permissions</a></p></li>
<li><p><a class="reference internal" href="#adapters" id="id28">Adapters</a></p></li>
<li><p><a class="reference internal" href="#wsgi-based-adapters" id="id29">WSGI-based Adapters</a></p></li>
<li><p><a class="reference internal" href="#scgi-based-adapters" id="id30">SCGI-based Adapters</a></p></li>
<li><p><a class="reference internal" href="#cgi-based-adapters" id="id31">CGI-based Adapters</a></p>
<ul>
<li><p><a class="reference internal" href="#id8" id="id32">wkcgi</a></p></li>
<li><p><a class="reference internal" href="#python-cgi-adapter" id="id33">Python CGI Adapter</a></p></li>
<li><p><a class="reference internal" href="#mod-webkit" id="id34">mod_webkit</a></p>
<ul>
<li><p><a class="reference internal" href="#posix-installation" id="id35">Posix Installation</a></p></li>
<li><p><a class="reference internal" href="#windows-installation" id="id36">Windows Installation</a></p></li>
<li><p><a class="reference internal" href="#apache-configuration" id="id37">Apache Configuration</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#fastcgi" id="id38">FastCGI</a></p></li>
<li><p><a class="reference internal" href="#mod-python" id="id39">mod_python</a></p></li>
<li><p><a class="reference internal" href="#oneshot" id="id40">OneShot</a></p></li>
<li><p><a class="reference internal" href="#isapi" id="id41">ISAPI</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#renaming-adapters" id="id42">Renaming Adapters</a></p></li>
<li><p><a class="reference internal" href="#adapter-problems-not-cgi" id="id43">Adapter Problems (not CGI)</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#configuration" id="id44">Configuration</a></p>
<ul>
<li><p><a class="reference internal" href="#sessions" id="id45">Sessions</a></p></li>
<li><p><a class="reference internal" href="#contexts" id="id46">Contexts</a></p></li>
<li><p><a class="reference internal" href="#creating-a-working-directory" id="id47">Creating a Working Directory</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#appserver-notes" id="id48">AppServer Notes</a></p>
<ul>
<li><p><a class="reference internal" href="#stopping-the-app-server" id="id49">Stopping the App Server</a></p></li>
<li><p><a class="reference internal" href="#reloading-servlets" id="id50">Reloading Servlets</a></p></li>
<li><p><a class="reference internal" href="#launching-the-appserver-at-unix-boot-up" id="id51">Launching the AppServer at Unix boot up</a></p>
<ul>
<li><p><a class="reference internal" href="#start-script-configuration" id="id52">Start script configuration</a></p></li>
<li><p><a class="reference internal" href="#activating-the-start-script" id="id53">Activating the start script</a></p></li>
<li><p><a class="reference internal" href="#using-systemd-to-start-the-appserver" id="id54">Using systemd to start the AppServer</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#running-threadedappserver-as-a-windows-nt-2k-xp-service" id="id55">Running ThreadedAppServer as a Windows NT/2K/XP Service</a></p></li>
<li><p><a class="reference internal" href="#other-notes" id="id56">Other Notes</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#troubleshooting" id="id57">Troubleshooting</a></p>
<ul>
<li><p><a class="reference internal" href="#bad-marshal-data" id="id58">Bad Marshal Data</a></p></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@lists.sourceforge.net">webware-discuss@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
<span class="docutils literal"><span class="pre">http://localhost:8080</span></span>.
The page you see is generated by <span class="docutils literal">WebKit/Examples/Welcome.py</span>.</p>
<p>If the AppServer fails with the error message <span class="docutils literal">Address already in use</span>,
you will need to tell it to use a different port number.
Edit <span class="docutils literal">WebKit/Configs/AppServer.config</span>, set <span class="docutils literal">AdapterPort</span>
and <span class="docutils literal">HTTPPort</span> 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 <span class="docutils literal">AppServer</span> or <span class="docutils literal">AppServer.bat</span> 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 slower.</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 <span class="docutils literal">import thread</span>. 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.
Web servers that support WSGI or SCGI can also be connected.
Apache is the best supported platform, both on Posix and Windows systems.</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 <span class="docutils literal">wkcgi.exe</span>) 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">> 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
<span class="docutils literal">WebKit/Adapters/wkcgi/wkcgi.exe</span>. 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 <span class="docutils literal">import socket</span>
to the top of the file (you could use a configuration file
instead, but this is easier). After creating the <span class="docutils literal">.exe</span> file, delete
<span class="docutils literal">WebKit.pyc</span> and rename <span class="docutils literal">WebKit.py</span> to <span class="docutils literal">_WebKit.py</span>. This will
avoid conflicts with <span class="docutils literal">WebKit.exe</span>.</p>
<p>There is also an ISAPI module for Webware in <span class="docutils literal">WebKit/Adapters/wkISAPI</span>
that needs to be compiled before use. However, there have been
problems with memory leaks in this adapter.</p>
</div>
<div class="section" id="other-servers">
<h3>Other Servers</h3>
<p>Other servers may support the <a class="reference internal" href="#wsgi-adapter">WSGI adapter</a> or <a class="reference internal" href="#scgi-connector">SCGI connector</a>,
otherwise you must resort to a <a class="reference internal" href="#cgi-adapter">CGI adapter</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>
<dl class="field-list simple">
<dt>Version</dt>
<dd><p>X.Y</p>
</dd>
<dt>Released</dt>
<dd><p>@@/@@/@@</p>
</dd>
</dl>
<p>You can check for the latest version at <a class="reference external" href="https://webwareforpython.github.io/w4py/">https://webwareforpython.github.io/w4py/</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="https://github.com/WebwareForPython/w4py">Webware GtiHub page</a>. You can find more information about Git in
general in the <a class="reference external" href="https://git-scm.com/documentation">Git Documentation</a>. The master branch 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>
<dt>Posix/Unix:</dt>
<dd><p>Nothing special to report. Both Linux and BSD have been used
with WebKit.</p>
</dd>
<dt>Windows 9x:</dt>
<dd><p>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.</p>
</dd>
<dt>Windows:</dt>
<dd><p>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 "r-strings". An example of a bad string is
<span class="docutils literal"><span class="pre">'C:\All\Web\'</span></span>. Good examples include:</p>
<ul class="simple">
<li><p><span class="docutils literal">'/All/Web'</span></p></li>
<li><p><span class="docutils literal"><span class="pre">'C:/All/Web'</span></span></p></li>
<li><p><span class="docutils literal"><span class="pre">'C:\\All\\Web'</span></span></p></li>
<li><p><span class="docutils literal"><span class="pre">'C:\All\Web'</span></span></p></li>
</ul>
<p>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 <span class="docutils literal">install.py</span> 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 <span class="docutils literal">install.py <span class="pre">-v</span></span> 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><p>The web browser</p></li>
<li><p>The web server</p></li>
<li><p>The app server</p></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
<span class="docutils literal">AppServer.config</span> setting <span class="docutils literal">EnableHTTP</span>. The port can be specified
with the setting <span class="docutils literal">HTTPPort</span> and will be <span class="docutils literal">8080</span> 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
<span class="docutils literal">AppServer.config</span> setting <span class="docutils literal">EnableAdapter</span>. The port can be specified
with the setting <span class="docutils literal">AdapterPort</span> and will be <span class="docutils literal">8086</span> by default.
You can use several app servers listening on different ports.</p>
<div class="section" id="id4">
<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><p>Cache</p></li>
<li><p>ErrorMsgs</p></li>
<li><p>Logs</p></li>
<li><p>Sessions</p></li>
</ul>
<p>The easiest way to do this is to make these directories writeable by
all (on Unix, that would be <span class="docutils literal">cd Webware/WebKit; chmod <span class="pre">-R</span> a+rwX Cache ErrorMsgs Logs Sessions</span>).</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><p><a class="reference internal" href="#wkcgi">wkcgi</a> (C-based CGI script)</p></li>
<li><p><a class="reference internal" href="#mod-webkit">mod_webkit</a> (fastest!)</p></li>
<li><p><a class="reference internal" href="#mod-scgi">mod_scgi</a> (equally fast, not included with Webware)</p></li>
<li><p><a class="reference internal" href="#mod-wsgi">mod_wsgi</a> (with the WSGIAdapter)</p></li>
</ul>
<p>These adapters are not really recommended:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#python-cgi-adapter">Python CGI Adapter</a></p></li>
<li><p><a class="reference internal" href="#fastcgi">FastCGI</a></p></li>
<li><p><a class="reference internal" href="#mod-python">mod_python</a> (with the ModPythonAdapter)</p></li>
<li><p><a class="reference internal" href="#isapi">ISAPI</a> (<em>alpha</em>, for IIS)</p></li>
<li><p><a class="reference internal" href="#oneshot">OneShot</a> (unusual to use, sometimes buggy)</p></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
web server 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 <span class="docutils literal">WebKit/Adapters/WSGIAdapter.py</span> 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 <span class="docutils literal">AppServer.config</span> setting <span class="docutils literal">EnableSCGI</span>.
The port can be specified with the setting <span class="docutils literal">SCGIPort</span> and will be <span class="docutils literal">8084</span>
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 the only option if none
of the other adapters are supported by the web server.</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="id8">
<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
<span class="docutils literal">WebKit/Adapters/wkcgi/wkcgi.exe</span>. 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 <span class="docutils literal">wkcgi</span>. You may want to rename it to
<span class="docutils literal">wkcgi.cgi</span>, since in some configurations files ending in <span class="docutils literal">.cgi</span>
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 <span class="docutils literal"><span class="pre">cgi-bin</span></span> directory, or in some
configurations it can be located anywhere so long as the filename ends
in <span class="docutils literal">.cgi</span> 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 (<span class="docutils literal">cd WebKit; ./AppServer</span>) and try again.</p>
<p>The AppServer may also be running on a non-standard host (i.e., not
<span class="docutils literal">localhost</span>) or a non-standard port (not 8086). If this is the
case, you must put a file <span class="docutils literal">webkit.cfg</span> 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
<span class="docutils literal">WebKit/Adapters/WebKit.cgi</span> -- you may wish to point the first line
(<span class="docutils literal"><span class="pre">#!/usr/bin/env</span> python</span>) to the actual path of the Python
interpreter (e.g., <span class="docutils literal"><span class="pre">#!/usr/local/bin/python</span></span>).</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 <span class="docutils literal">WebKit.cgi</span>
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
<span class="docutils literal">Webware/WebKit/Adapters/mod_webkit2</span> directory. You can also find an
older version for Apache 1.3 in <span class="docutils literal">Webware/WebKit/Adapters/mod_webkit1</span>,
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
<span class="docutils literal">make: /usr/sbin/apxs: Command not found</span>. This means the
<span class="docutils literal">apxs</span> 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><p>/usr/bin/apxs</p></li>
<li><p>/usr/local/bin/apxs</p></li>
<li><p>/usr/local/sbin/apxs</p></li>
<li><p>/usr/local/Apache-.../.../apxs</p></li>
</ul>
</blockquote>
<p>If you have an Apache directory under <span class="docutils literal">/usr/local</span>, you should
search it for the file. Execute the command <span class="docutils literal">find <span class="pre">/usr/local/Apache...</span> <span class="pre">-name</span> apxs</span> 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
<span class="docutils literal">Makefile</span> file in the mod_webkit directory. Where it says
<span class="docutils literal"><span class="pre">APXS=/usr/sbin/apxs</span></span>, change it to the appropriate location.</p>
<p><span class="docutils literal">make install</span> 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 <span class="docutils literal">WebKit/Adapters/mod_webkit2/mod_webkit.dll</span> into your Apache 2.2
module directory (usually located at
<span class="docutils literal"><span class="pre">C:\Program</span> Files\Apache Software Foundation\Apache2.2\modules\mod_webkit.so</span>).
You should also change the extension of the file to <span class="docutils literal">.so</span> according
to the Apache convention.</p>
<p>Edit <span class="docutils literal">httpd.conf</span> 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"><Location /WK>
WKServer localhost 8086
SetHandler webkit-handler
</Location></pre>
<p>Some Apache 2.2 users have found that they must use "127.0.0.1" instead
of "localhost", since Apache 2.2 defaults to using ipv6 addresses first.</p>
<p>With these lines, any URL that starts with <span class="docutils literal">/WK/</span> 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 <span class="docutils literal">/WK</span> portion to tell
mod_webkit where to find the AppServer.</p>
<p>To pass additional client HTTP headers through to the AppServer,
use the <span class="docutils literal">PassHeader</span> 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 <span class="docutils literal"><span class="pre">Accept-Language:</span> fr</span>,
the above code will set <span class="docutils literal">lang</span> to <span class="docutils literal">"fr"</span>.</p>
</div>
</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 <span class="docutils literal">WebKit/Adapters/FCGIAdapter.py</span> 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 <span class="docutils literal">WebKit/Adapters/ModPythonAdapter.py</span> 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="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 <span class="docutils literal">WebKit/Adapters/wkISAPI</span>.
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 <span class="docutils literal">serve.cgi</span>. 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,
<span class="docutils literal">WebKit/Configs/Application.config</span>.</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
<span class="docutils literal">SessionStore</span> setting determines where the data is stored and can
currently be set to <span class="docutils literal">Dynamic</span>, <span class="docutils literal">File</span>, <span class="docutils literal">Memcached</span>, <span class="docutils literal">Memory</span>,
<span class="docutils literal">Redis</span> or <span class="docutils literal">Shelve</span>.</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 periodically.
All sessions will be moved to disk when the server is stopped.
This storage mechanism works with both the persistent, long running
AppServers and <a class="reference internal" href="#oneshot">OneShot</a>. There are two settings in
<span class="docutils literal">Application.config</span> relating to this Dynamic session store.
<span class="docutils literal">MaxDynamicMemorySessions</span> specifies the maximum number of sessions
that can be in memory at any one time. <span class="docutils literal">DynamicSessionTimeout</span>
specifies after what period of time sessions will be moved from memory
to file. (Note: this setting is unrelated to the <span class="docutils literal">SessionTimeout</span>
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. Alternatively, using the redis-py client,
the AppServer can also store sessions in a Redis database.</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 <span class="docutils literal">SessionTimeout</span> 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><span class="docutils literal">Activity Log</span></p>
<p>Three options let you control:</p>
<blockquote>
<ul class="simple">
<li><p>Whether or not to log activity (<span class="docutils literal">LogActivity</span>, defaults to 0,
i.e. off)</p></li>
<li><p>The name of the file to store the log (<span class="docutils literal">ActivityLogFilename</span>,
defaults to <span class="docutils literal">Logs/Activity.csv</span>)</p></li>
<li><p>The fields to store in the log (<span class="docutils literal">ActivityLogColumns</span>) </ul></p></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><span class="docutils literal">EmailErrors</span>, <span class="docutils literal">ErrorEmailServer</span> and <span class="docutils literal">ErrorEmailHeaders</span> 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 <span class="docutils literal">Examples</span>,
<span class="docutils literal">Documentation</span> and <span class="docutils literal">Admin</span>. 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 "directory
partitioning". If you have two distinct web applications (for example,
<span class="docutils literal">PythonTutor</span> and <span class="docutils literal">DayTrader</span>), 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 <span class="docutils literal">Contexts</span> dictionary of
<span class="docutils literal">Application.config</span>. 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:
<span class="docutils literal"><span class="pre">http://localhost/WebKit.cgi/DayTrader/</span></span></p>
<p>The special name <span class="docutils literal">default</span> is reserved to specify what context is
served when none is specified (as in
<span class="docutils literal"><span class="pre">http://localhost/WebKit.cgi/</span></span>). Upon installation, this is the
<span class="docutils literal">Examples</span> context, which is convenient during development since it
provides links to all the other contexts.</p>
<p>Note that a context can contain an <span class="docutils literal">__init__.py</span> 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 <span class="docutils literal">bin/MakeAppWorkDir.py</span>. 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 search path.
You can see all of these options if you run <span class="docutils literal">bin/MakeAppWorkDir.py</span>
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="simple">
<dt><span class="docutils literal">AppServer</span>:</dt>
<dd><p>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 <span class="docutils literal">AppServer.bat</span>
instead and additionally, you will find a <span class="docutils literal">AppServerService.py</span>
script that can be used to start the AppServer as a service.</p>
</dd>
<dt><span class="docutils literal">Cache</span>:</dt>
<dd><p>A directory containing cache files. You won't need to look in here.</p>
</dd>
<dt><span class="docutils literal">Configs</span>:</dt>
<dd><p>Configuration files for the application. These files are copied from
<span class="docutils literal">WebKit/Configs</span>, but are specific to this application/AppServer.</p>
</dd>
<dt><span class="docutils literal">error404.html</span>:</dt>
<dd><p>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
<span class="docutils literal">ErrorPage</span> in the <span class="docutils literal">Application.config</span> file appropriately.</p>
</dd>
<dt><span class="docutils literal">ErrorMsgs</span>:</dt>
<dd><p>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.</p>
</dd>
<dt><span class="docutils literal">Launch.py</span>:</dt>
<dd><p>Called by the <span class="docutils literal">AppServer</span> script to launch the AppServer.</p>
</dd>
<dt><span class="docutils literal">Lib</span>:</dt>
<dd><p>An example for an application-specific library package that can be
created with the <span class="docutils literal"><span class="pre">-l</span></span> option (in this case, <span class="docutils literal"><span class="pre">-l</span> Lib</span>). Import
modules from this directory like <span class="docutils literal">from Lib.SitePage import SitePage</span>.</p>
</dd>
<dt><span class="docutils literal">Logs</span>:</dt>
<dd><p>Logs of accesses.</p>
</dd>
<dt><span class="docutils literal">MyContext</span>:</dt>
<dd><p>The directory for your default context. This is where you put your servlets.
you can change its name and location with the <span class="docutils literal"><span class="pre">`-c</span></span> and <span class="docutils literal"><span class="pre">-d</span></span> options.
You can also change this subsequently in the <span class="docutils literal">Application.config</span> file
in the <span class="docutils literal">Configs</span> 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.</p>
</dd>
<dt><span class="docutils literal">Sessions</span>:</dt>
<dd><p>Users sessions. These should be cleaned out automatically, you won't
have to look in this directory.</p>
</dd>
<dt><span class="docutils literal">WebKit.cgi</span>:</dt>
<dd><p>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 <span class="docutils literal">mod_webkit</span> or <span class="docutils literal">wkcgi</span>.</p>
</dd>
<dt><span class="docutils literal">webkit*</span>:</dt>
<dd><p>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>).</p>
</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 <span class="docutils literal">admin</span>, and the password is set when you run <span class="docutils literal">install.py</span>.
(You can change the password through the <span class="docutils literal">WebKit/Configs/Application.config</span>
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
<span class="docutils literal">./AppServer stop</span>.</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 "AppServer stop" doesn't work, you can use
<span class="docutils literal">ps <span class="pre">-ax</span> | grep ThreadedAppServer</span> to get the pid and <span class="docutils literal">kill <pid></span> 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, <span class="docutils literal">SitePage</span>,
<span class="docutils literal">AccountPage</span>, 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, <span class="docutils literal">ShoppingCart</span>, <span class="docutils literal">Story</span>, etc.), it won't be
reloaded.</p>
<p>While developing this will happen quite often. There is a setting in
<span class="docutils literal">WebKit/Configs/AppServer.config</span> that you should turn on early in
your experimentations.</p>
<p>The line:</p>
<pre class="literal-block">'AutoReload': 0,</pre>
<p>in <span class="docutils literal">AppServer.config</span> 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 <span class="docutils literal">WebKit/webkit</span> is a Unix shell script launching WebKit
at boot time through the standard System V mechanisms.</p>
<p>There are several variants of this script for various flavors of Unix
available in the folder <span class="docutils literal">WebKit/StartScripts/SysV</span>. The <span class="docutils literal">install.py</span>
script copies the variant that it thinks is the best fit to <span class="docutils literal">WebKit/webkit</span>.
If the script does not fit to your system, you may want to try out other
variants or the <span class="docutils literal">Generic</span> script that should fit on most systems.</p>
<p>If you create a working directory using <span class="docutils literal">bin/MakeAppWorkDir.py</span> as
explained above, the <span class="docutils literal">webkit</span> 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 <span class="docutils literal">/etc/init.d/</span>
(e.g. for SUSE or Debian Linux or Solaris) or <span class="docutils literal">/etc/rc.d/init.d/</span> (e.g. for
RedHat or Mandrake Linux). Instead of copying the script, you can also make
a symbolic link referring 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 <span class="docutils literal">root</span> as the Webware user, but
a user with the least possible permissions, maybe even <span class="docutils literal">nobody</span>.
By default, the start script uses the owner of the <span class="docutils literal">AppServer</span> script.</p>
<p>For the log file and the pid file, you may either use the standard locations
on your system, usually something like <span class="docutils literal">/var/log/webkit.log</span> and
<span class="docutils literal">/var/log/webkit.pid</span> (use different names for different instances),
or you may store them in the working directory and its <span class="docutils literal">Logs</span> 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 <span class="docutils literal">root</span> to restart the application server.
Therefore, the configuration section has another variable <span class="docutils literal">LAUNCH_AS_WEBWARE</span>
that determines whether Webware will launch as <span class="docutils literal">root</span> 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 <span class="docutils literal">LAUNCH_AS_WEBWARE</span> 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
<span class="docutils literal">appserver.pid</span>. 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 <span class="docutils literal">AppServer</span> which is
responsible for the AutoReload mechanism.</p>
<p>The start script also passes the variable <span class="docutils literal">PYTHONOPTS</span> to the <span class="docutils literal">AppServer</span>
script. You can add options <span class="docutils literal"><span class="pre">-U</span></span> for unbuffered output (to the log file)
or <span class="docutils literal"><span class="pre">-O</span></span> if you want to use optimized Python files (i.e. <span class="docutils literal">.pyo</span> instead
of <span class="docutils literal">.pyc</span>). You can also add additional Python libraries with <span class="docutils literal">PYTHONPATH</span>.</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">> ./webkit start</pre>
<p>The WebKit application server should now be launched and you should see
it in the output of the <span class="docutils literal">ps</span> command.</p>
<p>Also try to stop WebKit by typing:</p>
<pre class="literal-block">> ./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 <span class="docutils literal">/etc/init.d/webkit</span>, you would create the symbolic links like that:</p>
<pre class="literal-block">> cd /etc/rc0.d
> ln -s ../init.d/webkit K75webkit
(repeat for rc1.d and rc6.d)
> cd /etc/rc2.d
> 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
<span class="docutils literal">insserv</span> on SUSE Linux, <span class="docutils literal">chkconfig</span> for RedHat (Fedora),
<span class="docutils literal"><span class="pre">update-rc.d</span></span> for Debian (Ubuntu) or <span class="docutils literal"><span class="pre">rc-update</span></span> 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 <span class="docutils literal">man</span> pages or administrator handbook of your Unix
system for the details of installing start scripts.</p>
</div>
<div class="section" id="using-systemd-to-start-the-appserver">
<h3>Using systemd to start the AppServer</h3>
<p>Instead of using a System V start script, you can also use systemd to start
the AppServer. An example unit file can be found in the folder
<span class="docutils literal">WebKit/StartScripts/systemd</span>.</p>
<p>In order to install the unit file, it usually suffices to copy it to
<span class="docutils literal">/etc/systemd/system</span> and then run:</p>
<pre class="literal-block">> systemctl daemon-reload</pre>
<p>You need to configure it by editing the file, setting the WORK_DIR environment
variable properly and changing the options <span class="docutils literal"><span class="pre">-u</span></span> and <span class="docutils literal"><span class="pre">-g</span></span> for the Launch.py
script to the user and group that shall run the AppServer on your system.
After any change to the file, you need to run the above command again.</p>
<p>In order to manually start the AppServer, you can run the following command:</p>
<pre class="literal-block">> systemctl start webkit.service</pre>
</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><span class="docutils literal">AppServerService</span> is a script that runs the <span class="docutils literal">ThreadedAppServer</span>
as a Windows NT Service. This means it can be started and stopped
from the Control Panel or from the command line using <span class="docutils literal">net start</span>
and <span class="docutils literal">net stop</span>, 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><span class="docutils literal">AppServerService</span> 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 <span class="docutils literal">AppServerService.py</span> 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">> 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 "WebKit Application Server".
Or, from the command line, it can be started with either of
the following commands:</p>
<pre class="literal-block">> net start WebKit
> python AppServerService.py start</pre>
<p>The service can be stopped from the Control Panel or with:</p>
<pre class="literal-block">> net stop WebKit
> python AppServerService.py stop</pre>
<p>And finally, to uninstall the service, stop it and then run:</p>
<pre class="literal-block">> 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>