]> granicus.if.org Git - apache/blob - docs/manual/programs/apxs.xml
fix copyright notice
[apache] / docs / manual / programs / apxs.xml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Copyright 2003-2005 The Apache Software Foundation or its licensors,
8                      as applicable.
9
10  Licensed under the Apache License, Version 2.0 (the "License");
11  you may not use this file except in compliance with the License.
12  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="apxs.xml.meta">
24 <parentdocument href="./">Programs</parentdocument>
25
26 <title>apxs - APache eXtenSion tool</title>
27
28 <summary>
29     <p><code>apxs</code> is a tool for building and installing extension
30     modules for the Apache HyperText Transfer Protocol (HTTP) server. This is
31     achieved by building a dynamic shared object (DSO) from one or more source
32     or object <var>files</var> which then can be loaded into the Apache server
33     under runtime via the <directive module="mod_so">LoadModule</directive>
34     directive from <module>mod_so</module>.</p>
35
36     <p>So to use this extension mechanism your platform has to support the DSO
37     feature and your Apache <program>httpd</program> binary has to be built with the
38     <module>mod_so</module> module. The <code>apxs</code> tool automatically
39     complains if this is not the case. You can check this yourself by manually
40     running the command</p>
41
42     <example>
43       $ httpd -l
44     </example>
45
46     <p>The module <module>mod_so</module> should be part of the displayed list.
47     If these requirements are fulfilled you can easily extend your Apache
48     server's functionality by installing your own modules with the DSO mechanism
49     by the help of this <code>apxs</code> tool:</p>
50
51     <example>
52       $ apxs -i -a -c mod_foo.c<br />
53       gcc -fpic -DSHARED_MODULE -I/path/to/apache/include -c mod_foo.c<br />
54       ld -Bshareable -o mod_foo.so mod_foo.o<br />
55       cp mod_foo.so /path/to/apache/modules/mod_foo.so<br />
56       chmod 755 /path/to/apache/modules/mod_foo.so<br />
57       [activating module `foo' in /path/to/apache/etc/httpd.conf]<br />
58       $ apachectl restart<br />
59       /path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
60       [Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
61       /path/to/apache/sbin/apachectl restart: httpd started<br />
62       $ _
63     </example>
64
65     <p>The arguments <var>files</var> can be any C source file (.c), a object
66     file (.o) or even a library archive (.a). The <code>apxs</code> tool
67     automatically recognizes these extensions and  automatically used the C
68     source files for compilation while just using the object and archive files
69     for the linking phase. But when using such pre-compiled objects make sure
70     they are compiled for position independent code (PIC) to be able to use them
71     for a dynamically loaded shared object. For instance with GCC you always
72     just have to use <code>-fpic</code>. For other C compilers consult its
73     manual page or at watch for the flags <code>apxs</code> uses to compile the
74     object files.</p>
75
76     <p>For more details about DSO support in Apache read the documentation of
77     <module>mod_so</module> or perhaps even read the
78     <code>src/modules/standard/mod_so.c</code> source file.</p>
79 </summary>
80 <seealso><program>apachectl</program></seealso>
81 <seealso><program>httpd</program></seealso>
82
83 <section id="synopsis"><title>Synopsis</title>
84     <p><code><strong>apxs</strong> -<strong>g</strong>
85     [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
86     -<strong>n</strong> <var>modname</var></code></p>
87
88     <p><code><strong>apxs</strong> -<strong>q</strong>
89     [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
90     <var>query</var> ...</code></p>
91
92     <p><code><strong>apxs</strong> -<strong>c</strong>
93     [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
94     [ -<strong>o</strong> <var>dsofile</var> ]
95     [ -<strong>I</strong> <var>incdir</var> ]
96     [ -<strong>D</strong> <var>name</var>=<var>value</var> ]
97     [ -<strong>L</strong> <var>libdir</var> ]
98     [ -<strong>l</strong> <var>libname</var> ]
99     [ -<strong>Wc,</strong><var>compiler-flags</var> ]
100     [ -<strong>Wl,</strong><var>linker-flags</var> ]
101     <var>files</var> ...</code></p>
102
103     <p><code><strong>apxs</strong> -<strong>i</strong>
104     [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
105     [ -<strong>n</strong> <var>modname</var> ]
106     [ -<strong>a</strong> ]
107     [ -<strong>A</strong> ]
108     <var>dso-file</var> ...</code></p>
109
110     <p><code><strong>apxs</strong> -<strong>e</strong>
111     [ -<strong>S</strong> <var>name</var>=<var>value</var> ]
112     [ -<strong>n</strong> <var>modname</var> ]
113     [ -<strong>a</strong> ]
114     [ -<strong>A</strong> ]
115     <var>dso-file</var> ...</code></p>
116 </section>
117
118 <section id="options"><title>Options</title>
119     <section id="options.common"><title>Common Options</title>
120       <dl>
121       <dt><code>-n <var>modname</var></code></dt>
122       <dd>This explicitly sets the module name for the <code>-i</code> (install)
123       and <code>-g</code> (template generation) option. Use this to explicitly
124       specify the module name. For option <code>-g</code> this is required, for
125       option <code>-i</code> the <code>apxs</code> tool tries to determine the
126       name from the source or (as a fallback) at least by guessing it from the
127       filename.</dd>
128       </dl>
129     </section>
130
131     <section id="options.query"><title>Query Options</title>
132       <dl>
133       <dt><code>-q</code></dt>
134       <dd>Performs a query for <code>apxs</code>'s knowledge about certain
135       settings. The <var>query</var> parameters can be one or more of the
136       following strings: <code>CC</code>, <code>CFLAGS</code>,
137       <code>CFLAGS_SHLIB</code>, <code>INCLUDEDIR</code>, <code>LD_SHLIB</code>,
138       <code>LDFLAGS_SHLIB</code>, <code>LIBEXECDIR</code>,
139       <code>LIBS_SHLIB</code>, <code>SBINDIR</code>, <code>SYSCONFDIR</code>,
140       <code>TARGET</code>.
141
142       <p>Use this for manually determining settings. For instance use</p>
143       <example>
144         INC=-I`apxs -q INCLUDEDIR`
145       </example>
146
147       <p>inside your own Makefiles if you need manual access to Apache's C
148       header files.</p></dd>
149       </dl>
150     </section>
151
152     <section id="options.conf"><title>Configuration Options</title>
153       <dl>
154       <dt><code>-S <var>name</var>=<var>value</var></code></dt>
155       <dd>This option changes the apxs settings described above.</dd>
156       </dl>
157     </section>
158
159     <section id="options.template"><title>Template Generation Options</title>
160       <dl>
161       <dt><code>-g</code></dt>
162       <dd>This generates a subdirectory <var>name</var> (see option
163       <code>-n</code>) and there two files: A sample module source file named
164       <code>mod_<var>name</var>.c</code> which can be used as a template for
165       creating your own modules or as a quick start for playing with the
166       apxs mechanism. And a corresponding <code>Makefile</code> for even easier
167       build and installing of this module.</dd>
168       </dl>
169     </section>
170
171     <section id="options.dso"><title>DSO Compilation Options</title>
172       <dl>
173       <dt><code>-c</code></dt>
174       <dd>This indicates the compilation operation. It first compiles the C
175       source files (.c) of <var>files</var> into corresponding object files (.o)
176       and then builds a dynamically shared object in <var>dsofile</var> by
177       linking these object files plus the remaining object files (.o and .a) of
178       <var>files</var>. If no <code>-o</code> option is specified the output
179       file is guessed from the first filename in <var>files</var> and thus
180       usually defaults to <code>mod_<var>name</var>.so</code>.</dd>
181
182       <dt><code>-o <var>dsofile</var></code></dt>
183       <dd>Explicitly specifies the filename of the created dynamically shared
184       object. If not specified and the name cannot be guessed from the
185       <var>files</var> list, the fallback name <code>mod_unknown.so</code> is
186       used.</dd>
187
188       <dt><code>-D <var>name</var>=<var>value</var></code></dt>
189       <dd>This option is directly passed through to the compilation command(s).
190       Use this to add your own defines to the build process.</dd>
191
192       <dt><code>-I <var>incdir</var></code></dt>
193       <dd>This option is directly passed through to the compilation command(s).
194       Use this to add your own include directories to search to the build
195       process.</dd>
196
197       <dt><code>-L <var>libdir</var></code></dt>
198       <dd>This option is directly passed through to the linker command. Use this
199       to add your own library directories to search to the build  process.</dd>
200
201       <dt><code>-l <var>libname</var></code></dt>
202       <dd>This option is directly passed through to the linker command. Use this
203       to add your own libraries to search to the build process.</dd>
204
205       <dt><code>-Wc,<var>compiler-flags</var></code></dt>
206       <dd>This option passes <var>compiler-flags</var> as additional flags to
207       the <code>libtool --mode=compile</code> command. Use this to add local
208       compiler-specific options.</dd>
209
210       <dt><code>-Wl,<var>linker-flags</var></code></dt>
211       <dd>This option passes <var>linker-flags</var> as additional
212       flags to the <code>libtool --mode=link</code> command. Use this
213       to add local linker-specific options.</dd>
214       </dl>
215     </section>
216
217     <section id="options.dsoinstall">
218     <title>DSO Installation and Configuration Options</title>
219       <dl>
220       <dt><code>-i</code></dt>
221       <dd>This indicates the installation operation and installs one or more
222       dynamically shared objects into the server's <var>modules</var>
223       directory.</dd>
224
225       <dt><code>-a</code></dt>
226       <dd>This activates the module by automatically adding a corresponding
227       <directive module="mod_so">LoadModule</directive> line to Apache's
228       <code>httpd.conf</code> configuration file, or by enabling it if it
229       already exists.</dd>
230
231       <dt><code>-A</code></dt>
232       <dd>Same as option <code>-a</code> but the created <directive
233       module="mod_so">LoadModule</directive> directive is prefixed with a hash
234       sign (<code>#</code>), <em>i.e.</em>, the module is just prepared for
235       later activation but initially disabled.</dd>
236
237       <dt><code>-e</code></dt>
238       <dd>This indicates the editing operation, which can be used with the
239       <code>-a</code> and <code>-A</code> options similarly to the
240       <code>-i</code> operation to edit Apache's <code>httpd.conf</code>
241       configuration file without attempting to install the module.</dd>
242       </dl>
243     </section>
244 </section>
245
246 <section id="examples"><title>Examples</title>
247     <p>Assume you have an Apache module named <code>mod_foo.c</code> available
248     which should extend Apache's server functionality. To accomplish this you
249     first have to compile the C source into a shared object suitable for loading
250     into the Apache server under runtime via the following command:</p>
251
252     <example>
253       $ apxs -c mod_foo.c<br />
254       /path/to/libtool --mode=compile gcc ... -c mod_foo.c<br />
255       /path/to/libtool --mode=link gcc ... -o mod_foo.la mod_foo.slo<br />
256       $ _
257     </example>
258
259     <p>Then you have to update the Apache configuration by making sure a
260     <directive module="mod_so">LoadModule</directive> directive is present to
261     load this shared object. To simplify this step <code>apxs</code> provides
262     an automatic way to install the shared object in its "modules" directory
263     and updating the <code>httpd.conf</code> file accordingly. This can be
264     achieved by running:</p>
265
266     <example>
267       $ apxs -i -a mod_foo.la<br />
268       /path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
269       /path/to/libtool --mode=install cp mod_foo.la /path/to/apache/modules
270       ...
271       chmod 755 /path/to/apache/modules/mod_foo.so<br />
272       [activating module `foo' in /path/to/apache/conf/httpd.conf]<br />
273       $ _
274     </example>
275
276     <p>This way a line named</p>
277
278     <example>
279       LoadModule foo_module modules/mod_foo.so
280     </example>
281
282     <p>is added to the configuration file if still not present. If you want to
283     have this disabled per default use the <code>-A</code> option,
284     <em>i.e.</em></p>
285
286     <example>
287       $ apxs -i -A mod_foo.c
288     </example>
289
290     <p>For a quick test of the apxs mechanism you can create a sample Apache
291     module template plus a corresponding Makefile via:</p>
292
293     <example>
294       $ apxs -g -n foo<br />
295       Creating [DIR]  foo<br />
296       Creating [FILE] foo/Makefile<br />
297       Creating [FILE] foo/modules.mk<br />
298       Creating [FILE] foo/mod_foo.c<br />
299       Creating [FILE] foo/.deps<br />
300       $ _
301     </example>
302
303     <p>Then you can immediately compile this sample module into a shared object
304     and load it into the Apache server:</p>
305
306     <example>
307       $ cd foo<br />
308       $ make all reload<br />
309       apxs -c mod_foo.c<br />
310       /path/to/libtool --mode=compile gcc ... -c mod_foo.c<br />
311       /path/to/libtool --mode=link gcc ... -o mod_foo.la mod_foo.slo<br />
312       apxs -i -a -n "foo" mod_foo.la<br />
313       /path/to/instdso.sh mod_foo.la /path/to/apache/modules<br />
314       /path/to/libtool --mode=install cp mod_foo.la /path/to/apache/modules
315       ...
316       chmod 755 /path/to/apache/modules/mod_foo.so<br />
317       [activating module `foo' in /path/to/apache/conf/httpd.conf]<br />
318       apachectl restart<br />
319       /path/to/apache/sbin/apachectl restart: httpd not running, trying to start<br />
320       [Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module<br />
321       /path/to/apache/sbin/apachectl restart: httpd started<br />
322       $ _
323     </example>
324
325 </section>
326 </manualpage>