File: modpython2.tex

package info (click to toggle)
libapache-mod-python 2%3A2.7.8-0.0woody5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,312 kB
  • ctags: 850
  • sloc: ansic: 2,782; python: 1,115; makefile: 260; sh: 246
file content (340 lines) | stat: -rw-r--r-- 10,881 bytes parent folder | download | duplicates (3)
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
\chapter{Installation\label{installation}}
\indexii{installation}{UNIX}
\indexii{mod_python}{mailing list}
NOTE: By far the best place to get help with installation and other
issues is the mod_python mailing list. Please take a moment to join
the mod_python mailing list by sending an e-mail with the word
"subscribe" in the subject to \email{mod_python-request@modpython.org}.

\section{Prerequisites\label{inst-prerequisites}}

\begin{itemize}
\item
Python 1.5.2, 1.6, 2.0 or 2.1
\item
Apache 1.3 (1.3.20 or higher recommended, 2.0 is not yet supported) 
\end{itemize}

You will need to have the include files for both Apache and Python, as
well as the Python library installed on your system.  If you installed
Python and Apache from source, then you already have everything that's
needed. However, if you are using prepackaged software (e.g. Linux Red
Hat RPM, Debian, or Solaris packages from sunsite, etc) then chances
are, you just have the binaries and not the sources on your
system. Often, the include files and the libraries are part of
separate "development" package. If you are not sure whether you have
all the necessary files, either compile and install Python and Apache
from source, or refer to the documentation for your system on how to
get the development packages.

\section{Compiling\label{inst-compiling}}

There are two ways that this module can be compiled and linked to
Apache - statically, or as a DSO (Dynamic Shared Object).

\dfn{Static} linking is a more "traditional" approach, and most programmers
prefer it for its simplicity. The drawback is that it entails
recompiling Apache, which some people cannot do for a variety of
reasons. 

\dfn{DSO} is a newer and still somewhat experimental
approach. The module gets compiled as a library that is dynamically
loaded by the server at run time. A more detailed description of the
Apache DSO mechanism is available at
\url{http://www.apache.org/docs/dso.html}.

The advantage of DSO is that a module can be installed without
recompiling Apache and used as needed. DSO has its disadvantages,
however. Compiling a module like mod_python into a DSO can be a
complicated process because Python, depending on configuration, may
rely on a number of other libraries, and you need to make sure that
the DSO is statically linked against each of them. Luckily, the
configure script below will spare you of this headache by
automatically figuring out all the necessary parameters.

\subsection{Running ./configure\label{inst-configure}}
\index{./configure}

The \program{./configure} script will analyze your environment and create custom
Makefiles particular to your system. Aside from all the standard
autoconf stuff, \program{./configure} does the following:

\begin{itemize}

\item
\index{apxs}
\indexii{./configure}{\longprogramopt{with-apxs}}
Finds out whether a program called \program{apxs} is available. This
program is part of the standard Apache distribution, and is necessary
for DSO compilation. If apxs cannot be found in your \envvar{PATH} or in
\filenq{/usr/local/apache/bin}, DSO compilation will not be available.

You can manually specify the location of apxs by using the
\longprogramopt{with-apxs} option, e.g.:

\begin{verbatim}
$ ./configure --with-apxs=/usr/local/apache/bin/apxs 	
\end{verbatim}
%$ keep emacs happy

\item
\indexii{./configure}{\longprogramopt{with-apache}}
Checks for \longprogramopt{with-apache} option. Use this option to
tell \program{./configure} where the Apache sources are on your
system. The Apache sources are necessary for static compilation. If
you do not specify this option, static compilation will not be
available. Here is an example:

\begin{verbatim}
$ ./configure --with-apache=../src/apache_1.3.12 --with-apxs=/usr/local/apache/bin/apxs
\end{verbatim}
%$ keep emacs happy

\item
\index{libpython.a}
Checks your Python version and attempts to figure out where
\program{libpython} is by looking at various parameters compiled into
your Python binary. By default, it will use the \program{python}
program found in your \envvar{PATH}.

\indexii{./configure}{\longprogramopt{with-python}}
If the Python installation on your system is not suitable for
mod_python (which can be the case if Python is compiled with thread
support), you can specify an alternative location with the
\longprogramopt{with-python} options. This option needs to point to
the root directory of the Python source, e.g.:

\begin{verbatim}
$ ./configure --with-python=/usr/local/src/Python-2.0
\end{verbatim}                      
%$ keep emacs happy

Note that the directory needs to contain already configured and
compiled Python. In other words, you must at least run \program{./configure} and
\program{make}.

Also note that while it is possible to point the \longprogramopt{with-python}
to a version of Python different from the one installed in your standard
\envvar{PATH}, you will need to have that version of Python installed as well.
This is because the path to the Python library, which is retrieved from the
\file{python} binary is going to point to the
place where Python would be ultimately installed, not the source
deirectory. Generally, it's best to try to keep the version of Python that
you use for mod_python the same as the one you use everywhere on the system.

\end{itemize}

\subsection{Running make\label{inst-make}}

\begin{itemize}

\item
If possible, the \program{./configure} script will default to DSO
compilation, otherwise, it will default to static. To stay with
whatever \program{./configure} decided, simply run
\begin{verbatim}
$ make
\end{verbatim}
%$ emacs happy

\indexii{make targets}{static}
\indexii{make targets}{dso}

Or, if you would like to be specific, give \program{make} a
\programopt{dso} or \programopt{static} target:
\begin{verbatim}
$ make dso
\end{verbatim}
%$ emacs happy
OR
\begin{verbatim}
$ make static
\end{verbatim}
%$

\end{itemize}

\section{Installing\label{inst-installing}}

\subsection{Running make install\label{inst-makeinstall}}

\begin{itemize}

\item
This part of the installation needs to be done as root. 
\begin{verbatim}
$ su
# make install
\end{verbatim}
%$ emacs happy
                      
\begin{itemize}

\item
For DSO, this will simply copy the library into your Apache \filenq{libexec}
directory, where all the other modules are.

\item
For static, it will copy some files into your Apache source tree.

\item
Lastly, it will install the Python libraries in \filenq{site-packages} and
compile them. 

\end{itemize} 

\indexii{make targets}{install_py_lib}
\indexii{make targets}{install_static}
\indexii{make targets}{install_dso}
\strong{NB:} If you wish to selectively install just the Python libraries,
the static library or the DSO (which may not always require superuser
privileges), you can use the following \program{make} targets:
\programopt{install_py_lib},
\programopt{install_static} and \programopt{install_dso}

\end{itemize}

\subsection{Configuring Apache\label{inst-apacheconfig}}

\begin{itemize}

\item
If you compiled mod_python as a DSO, you will need to tell Apache to
load the module by adding the following line in the Apache
configuration file, usually called \filenq{httpd.conf} or
\filenq{apache.conf}:

\begin{verbatim}
LoadModule python_module libexec/mod_python.so
\end{verbatim}

\index{mod_python.so}
The actual path to \program{mod_python.so} may vary, but make install
should report at the very end exactly where \program{mod_python.so}
was placed and how the \code{LoadModule} directive should appear.

If your Apache configuration uses \code{ClearModuleList} directive,
you will need to add mod_python to the module list in the Apache
configuration file:

\begin{verbatim}
AddModule mod_python.c
\end{verbatim}

\strong{NB:} 
Some (not all) RedHat Linux users reported that mod_python needs to be
first in the module list, or Apache will crash.

\item
If you used the static installation, you now need to recompile Apache: 

\begin{verbatim}
$ cd ../src/apache_1.3.12
$ ./configure --activate-module=src/modules/python/libpython.a
$ make
\end{verbatim}
%$ emacs happy
                            
Or, if you prefer the old "Configure" style, edit
\filenq{src/Configuration} to have

\begin{verbatim}
AddModule modules/python/libpython.a
\end{verbatim}
then run 
\begin{verbatim}
$ cd src
$ ./Configure
$ Make
\end{verbatim}
%$ emacs happy

\end{itemize}

\section{Testing\label{inst-testing}}

\begin{enumerate}

\item
Make some directory that would be visible on your web site, for
example, htdocs/test.

\item
Add the following Apache directives, which can appear in either the
main server configuration file, or \filenq{.htaccess}.  If you are going
to be using the \filenq{.htaccess} file, you will not need the
\code{<Directory>} tag below, and you will need to make sure the
\code{AllowOverride} directive applicable to this directory has at least
\code{FileInfo} specified. (The default is \code{None}, which will not work.)

\begin{verbatim}
<Directory /some/directory/htdocs/test> 
  AddHandler python-program .py
  PythonHandler mptest 
  PythonDebug On 
</Directory>
\end{verbatim}

(Substitute \filenq{/some/directory} above for something applicable to
your system, usually your Apache ServerRoot)

\item
At this time, if you made changes to the main configuration file, you
will need to restart Apache in order for the changes to take effect.

\item
Edit \filenq{mptest.py} file in the \filenq{htdocs/test} directory so
that is has the following lines (be careful when cutting and pasting
from your browser, you may end up with incorrect indentation and a
syntax error):

\begin{verbatim}
from mod_python import apache

def handler(req):
    req.send_http_header()
    req.write("Hello World!")
    return apache.OK 
\end{verbatim}

\item
Point your browser to the URL referring to the \filenq{mptest.py}; you
should see \code{"Hello World!"}. If you didn't - refer to the
troubleshooting section next.

\item
If everything worked well, move on to Chapter \ref{tutorial}, 
\citetitle[tutorial.html]{Tutorial}. 

\end{enumerate}

\section{Troubleshooting\label{inst-trouble}}

There are a couple things you can try to identify the problem: 

\begin{itemize}

\item Carefully study the error output, if any. 

\item Check the server error log file, it may contain useful clues. 

\item Try running Apache from the command line with an -X argument: 
\begin{verbatim}
                  ./httpd -X
\end{verbatim}
This prevents it from backgrounding itself and may provide some useful information. 

\item
Ask on the mod_python list. Make sure to provide specifics such as:

\begin{itemize}

\item Your operating system type, name and version.
\item Your Python version, and any unusual compilation options.
\item Your Apache version.
\item Relevant parts of the Apache config, .htaccess.
\item Relevant parts of the Python code.

\end{itemize}

\end{itemize}