summaryrefslogtreecommitdiffstats
path: root/docs/manual/programs/apxs.xml
blob: 309fccfe1189022bcf2f1b1c281cb2b08f3dc040 (plain)
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
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
<!-- $LastChangedRevision$ -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<manualpage metafile="apxs.xml.meta">
<parentdocument href="./">Programs</parentdocument>

<title>apxs - APache eXtenSion tool</title>

<summary>
    <p><code>apxs</code> is a tool for building and installing extension
    modules for the Apache HyperText Transfer Protocol (HTTP) server. This is
    achieved by building a dynamic shared object (DSO) from one or more source
    or object <var>files</var> which then can be loaded into the Apache server
    under runtime via the <directive module="mod_so">LoadModule</directive>
    directive from <module>mod_so</module>.</p>

    <p>So to use this extension mechanism your platform has to support the DSO
    feature and your Apache <program>httpd</program> binary has to be built with the
    <module>mod_so</module> module. The <code>apxs</code> tool automatically
    complains if this is not the case. You can check this yourself by manually
    running the command</p>

    <example>
      $ httpd -l
    </example>

    <p>The module <module>mod_so</module> should be part of the displayed list.
    If these requirements are fulfilled you can easily extend your Apache
    server's functionality by installing your own modules with the DSO mechanism
    by the help of this <code>apxs</code> tool:</p>

    <example>
      $ apxs -i -a -c mod_foo.c<br />
      gcc -fpic -DSHARED_MODULE -I/path/to/apache/include -c mod_foo.c<br />
      ld -Bshareable -o mod_foo.so mod_foo.o<br />
      cp mod_foo.so /path/to/apache/modules/mod_foo.so<br />
      chmod 755 /path/to/apache/modules/mod_foo.so<br />
      [activating module `foo' in /path/to/apache/etc/httpd.conf]<br />
      $ apachectl restart<br />
      /path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
      [Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
      /path/to/apache/sbin/apachectl restart: httpd started<br />
      $ _
    </example>

    <p>The arguments <var>files</var> can be any C source file (.c), a object
    file (.o) or even a library archive (.a). The <code>apxs</code> tool
    automatically recognizes these extensions and  automatically used the C
    source files for compilation while just using the object and archive files
    for the linking phase. But when using such pre-compiled objects make sure
    they are compiled for position independent code (PIC) to be able to use them
    for a dynamically loaded shared object. For instance with GCC you always
    just have to use <code>-fpic</code>. For other C compilers consult its
    manual page or at watch for the flags <code>apxs</code> uses to compile the
    object files.</p>

    <p>For more details about DSO support in Apache read the documentation of
    <module>mod_so</module> or perhaps even read the
    <code>src/modules/standard/mod_so.c</code> source file.</p>
</summary>
<seealso><program>apachectl</program></seealso>
<seealso><program>httpd</program></seealso>

<section id="synopsis"><title>Synopsis</title>
    <p><code><strong>apxs</strong> -<strong>g</strong>
    [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
    -<strong>n</strong> <var>modname</var></code></p>

    <p><code><strong>apxs</strong> -<strong>q</strong>
    [ -<strong>v</strong> ]
    [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
    <var>query</var> ...</code></p>

    <p><code><strong>apxs</strong> -<strong>c</strong>
    [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
    [ -<strong>o</strong> <var>dsofile</var> ]
    [ -<strong>I</strong> <var>incdir</var> ]
    [ -<strong>D</strong> <var>name</var>=<var>value</var> ]
    [ -<strong>L</strong> <var>libdir</var> ]
    [ -<strong>l</strong> <var>libname</var> ]
    [ -<strong>Wc,</strong><var>compiler-flags</var> ]
    [ -<strong>Wl,</strong><var>linker-flags</var> ]
    <var>files</var> ...</code></p>

    <p><code><strong>apxs</strong> -<strong>i</strong>
    [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
    [ -<strong>n</strong> <var>modname</var> ]
    [ -<strong>a</strong> ]
    [ -<strong>A</strong> ]
    <var>dso-file</var> ...</code></p>

    <p><code><strong>apxs</strong> -<strong>e</strong>
    [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
    [ -<strong>n</strong> <var>modname</var> ]
    [ -<strong>a</strong> ]
    [ -<strong>A</strong> ]
    <var>dso-file</var> ...</code></p>
</section>

<section id="options"><title>Options</title>
    <section id="options.common"><title>Common Options</title>
      <dl>
      <dt><code>-n <var>modname</var></code></dt>
      <dd>This explicitly sets the module name for the <code>-i</code> (install)
      and <code>-g</code> (template generation) option. Use this to explicitly
      specify the module name. For option <code>-g</code> this is required, for
      option <code>-i</code> the <code>apxs</code> tool tries to determine the
      name from the source or (as a fallback) at least by guessing it from the
      filename.</dd>
      </dl>
    </section>

    <section id="options.query"><title>Query Options</title>
      <dl>
      <dt><code>-q</code></dt>
      <dd>Performs a query for variables and environment settings used to
      build <code>httpd</code>.  When invoked without <var>query</var> parameters,
      it prints all known variables and their values.  The optional <code>-v</code>
      parameter formats the list output.

      <p>Use this to manually determine settings used to build the
      <code>httpd</code> that will load your module.  For instance use</p>
      <example>
        INC=-I`apxs -q INCLUDEDIR`
      </example>

      <p>inside your own Makefiles if you need manual access to Apache's C
      header files.</p></dd>
      </dl>
    </section>

    <section id="options.conf"><title>Configuration Options</title>
      <dl>
      <dt><code>-S <var>name</var>=<var>value</var></code></dt>
      <dd>This option changes the apxs settings described above.</dd>
      </dl>
    </section>

    <section id="options.template"><title>Template Generation Options</title>
      <dl>
      <dt><code>-g</code></dt>
      <dd>This generates a subdirectory <var>name</var> (see option
      <code>-n</code>) and there two files: A sample module source file named
      <code>mod_<var>name</var>.c</code> which can be used as a template for
      creating your own modules or as a quick start for playing with the
      apxs mechanism. And a corresponding <code>Makefile</code> for even easier
      build and installing of this module.</dd>
      </dl>
    </section>

    <section id="options.dso"><title>DSO Compilation Options</title>
      <dl>
      <dt><code>-c</code></dt>
      <dd>This indicates the compilation operation. It first compiles the C
      source files (.c) of <var>files</var> into corresponding object files (.o)
      and then builds a dynamically shared object in <var>dsofile</var> by
      linking these object files plus the remaining object files (.o and .a) of
      <var>files</var>. If no <code>-o</code> option is specified the output
      file is guessed from the first filename in <var>files</var> and thus
      usually defaults to <code>mod_<var>name</var>.so</code>.</dd>

      <dt><code>-o <var>dsofile</var></code></dt>
      <dd>Explicitly specifies the filename of the created dynamically shared
      object. If not specified and the name cannot be guessed from the
      <var>files</var> list, the fallback name <code>mod_unknown.so</code> is
      used.</dd>

      <dt><code>-D <var>name</var>=<var>value</var></code></dt>
      <dd>This option is directly passed through to the compilation command(s).
      Use this to add your own defines to the build process.</dd>

      <dt><code>-I <var>incdir</var></code></dt>
      <dd>This option is directly passed through to the compilation command(s).
      Use this to add your own include directories to search to the build
      process.</dd>

      <dt><code>-L <var>libdir</var></code></dt>
      <dd>This option is directly passed through to the linker command. Use this
      to add your own library directories to search to the build  process.</dd>

      <dt><code>-l <var>libname</var></code></dt>
      <dd>This option is directly passed through to the linker command. Use this
      to add your own libraries to search to the build process.</dd>

      <dt><code>-Wc,<var>compiler-flags</var></code></dt>
      <dd>This option passes <var>compiler-flags</var> as additional flags to
      the <code>libtool --mode=compile</code> command. Use this to add local
      compiler-specific options.</dd>

      <dt><code>-Wl,<var>linker-flags</var></code></dt>
      <dd>This option passes <var>linker-flags</var> as additional
      flags to the <code>libtool --mode=link</code> command. Use this
      to add local linker-specific options.</dd>
      </dl>
    </section>

    <section id="options.dsoinstall">
    <title>DSO Installation and Configuration Options</title>
      <dl>
      <dt><code>-i</code></dt>
      <dd>This indicates the installation operation and installs one or more
      dynamically shared objects into the server's <var>modules</var>
      directory.</dd>

      <dt><code>-a</code></dt>
      <dd>This activates the module by automatically adding a corresponding
      <directive module="mod_so">LoadModule</directive> line to Apache's
      <code>httpd.conf</code> configuration file, or by enabling it if it
      already exists.</dd>

      <dt><code>-A</code></dt>
      <dd>Same as option <code>-a</code> but the created <directive
      module="mod_so">LoadModule</directive> directive is prefixed with a hash
      sign (<code>#</code>), <em>i.e.</em>, the module is just prepared for
      later activation but initially disabled.</dd>

      <dt><code>-e</code></dt>
      <dd>This indicates the editing operation, which can be used with the
      <code>-a</code> and <code>-A</code> options similarly to the
      <code>-i</code> operation to edit Apache's <code>httpd.conf</code>
      configuration file without attempting to install the module.</dd>
      </dl>
    </section>
</section>

<section id="examples"><title>Examples</title>
    <p>Assume you have an Apache module named <code>mod_foo.c</code> available
    which should extend Apache's server functionality. To accomplish this you
    first have to compile the C source into a shared object suitable for loading
    into the Apache server under runtime via the following command:</p>

    <example>
      $ apxs -c mod_foo.c<br />
      /path/to/libtool --mode=compile gcc ... -c mod_foo.c<br />
      /path/to/libtool --mode=link gcc ... -o mod_foo.la mod_foo.slo<br />
      $ _
    </example>

    <p>Then you have to update the Apache configuration by making sure a
    <directive module="mod_so">LoadModule</directive> directive is present to
    load this shared object. To simplify this step <code>apxs</code> provides
    an automatic way to install the shared object in its "modules" directory
    and updating the <code>httpd.conf</code> file accordingly. This can be
    achieved by running:</p>

    <example>
      $ apxs -i -a mod_foo.la<br />
      /path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
      /path/to/libtool --mode=install cp mod_foo.la /path/to/apache/modules
      ...
      chmod 755 /path/to/apache/modules/mod_foo.so<br />
      [activating module `foo' in /path/to/apache/conf/httpd.conf]<br />
      $ _
    </example>

    <p>This way a line named</p>

    <example>
      LoadModule foo_module modules/mod_foo.so
    </example>

    <p>is added to the configuration file if still not present. If you want to
    have this disabled per default use the <code>-A</code> option,
    <em>i.e.</em></p>

    <example>
      $ apxs -i -A mod_foo.c
    </example>

    <p>For a quick test of the apxs mechanism you can create a sample Apache
    module template plus a corresponding Makefile via:</p>

    <example>
      $ apxs -g -n foo<br />
      Creating [DIR]  foo<br />
      Creating [FILE] foo/Makefile<br />
      Creating [FILE] foo/modules.mk<br />
      Creating [FILE] foo/mod_foo.c<br />
      Creating [FILE] foo/.deps<br />
      $ _
    </example>

    <p>Then you can immediately compile this sample module into a shared object
    and load it into the Apache server:</p>

    <example>
      $ cd foo<br />
      $ make all reload<br />
      apxs -c mod_foo.c<br />
      /path/to/libtool --mode=compile gcc ... -c mod_foo.c<br />
      /path/to/libtool --mode=link gcc ... -o mod_foo.la mod_foo.slo<br />
      apxs -i -a -n "foo" mod_foo.la<br />
      /path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
      /path/to/libtool --mode=install cp mod_foo.la /path/to/apache/modules
      ...
      chmod 755 /path/to/apache/modules/mod_foo.so<br />
      [activating module `foo' in /path/to/apache/conf/httpd.conf]<br />
      apachectl restart<br />
      /path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
      [Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
      /path/to/apache/sbin/apachectl restart: httpd started<br />
      $ _
    </example>

</section>
</manualpage>