.\" $OpenBSD: apxs.8,v 1.15 2007/05/31 19:20:24 jmc Exp $ .\" .\" ==================================================================== .\" The Apache Software License, Version 1.1 .\" .\" Copyright (c) 2000-2003 The Apache Software Foundation. All rights .\" reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" 3. The end-user documentation included with the redistribution, .\" if any, must include the following acknowledgment: .\" "This product includes software developed by the .\" Apache Software Foundation (http://www.apache.org/)." .\" Alternately, this acknowledgment may appear in the software itself, .\" if and wherever such third-party acknowledgments normally appear. .\" .\" 4. The names "Apache" and "Apache Software Foundation" must .\" not be used to endorse or promote products derived from this .\" software without prior written permission. For written .\" permission, please contact apache@apache.org. .\" .\" 5. Products derived from this software may not be called "Apache", .\" nor may "Apache" appear in their name, without prior written .\" permission of the Apache Software Foundation. .\" .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED .\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE .\" DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" ==================================================================== .\" .\" This software consists of voluntary contributions made by many .\" individuals on behalf of the Apache Software Foundation. For more .\" information on the Apache Software Foundation, please see .\" <http://www.apache.org/>. .\" .\" Portions of this software are based upon public domain software .\" originally written at the National Center for Supercomputing Applications, .\" University of Illinois, Urbana-Champaign. .\" .Dd $Mdocdate: May 31 2007 $ .Dt APXS 8 .Os .Sh NAME .Nm apxs .Nd APache eXtenSion tool .Sh SYNOPSIS .Nm .Bk -words .Fl c .Xo .Oo Fl D .Ar variable Ns Oo = Ns Ar value Oc Oc .Xc .Op Fl I Ar incdir .Op Fl L Ar libdir .Op Fl l Ar libname .No \ \&\ \& Op Fl o Ar dsofile .Xo .Oo Fl S .Ar variable Ns = Ns Ar value Oc .Xc .Op Fl Wc , Ns Ar compiler-flags .No \ \&\ \& Op Fl Wl , Ns Ar linker-flags .Ar file ... .Ek .Nm .Fl e .Op Fl Aa .Op Fl n Ar name .Xo .Oo Fl S .Ar variable Ns = Ns Ar value Oc .Xc .Ar dsofile ... .Nm .Fl g .Xo .Oo Fl S .Ar variable Ns = Ns Ar value Oc .Xc .Fl n Ar name .Nm .Fl i .Op Fl Aa .Op Fl n Ar name .Xo .Oo Fl S .Ar variable Ns = Ns Ar value Oc .Xc .Ar dsofile ... .Nm .Fl q .Xo .Oo Fl S .Ar variable Ns = Ns Ar value Oc .Xc .Ar query ... .Sh DESCRIPTION .Nm is a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server, .Xr httpd 8 . This is achieved by building a Dynamic Shared Object (DSO) from one or more source or object files which can then be loaded into httpd at runtime via the .Ic LoadModule directive from .Ic mod_so . To use this extension mechanism, your platform has to support the DSO feature and the httpd binary has to be built with the .Ic mod_so module. The .Nm tool automatically complains if this is not the case. Check by manually running the following command: .Pp .Dl $ httpd -l .Pp The module .Ic mod_so should be part of the displayed list. If these requirements are fulfilled, httpd's functionality can be extended by installing modules with the DSO mechanism, with the help of the .Nm tool: .Bd -literal -offset indent # apxs -i -a -c mod_foo.c cc -O2 -pipe -DDEV_RANDOM=/dev/arandom -DMOD_SSL=208116 -DEAPI -DUSE_EXPAT -I../lib/expat-lite -DUSE_SETUSERCONTEXT -fPIC -DSHARED_MODULE -I/usr/lib/apache/include -c mod_foo.c [activating module `foo' in /var/www/conf/httpd.conf] cp mod_foo.so /usr/lib/apache/modules/mod_foo.so chmod 755 /usr/lib/apache/modules/mod_foo.so cp /var/www/conf/httpd.conf /var/www/conf/httpd.conf.bak cp /var/www/conf/httpd.conf.new /var/www/conf/httpd.conf rm /var/www/conf/httpd.conf.new # apachectl restart /usr/sbin/apachectl restart: httpd not running, trying to start /usr/sbin/apachectl restart: httpd started .Ed .Pp The argument .Ar file can be any C source file (.c), an object file (.o), or even a library archive (.a). The .Nm tool automatically recognizes these extensions and automatically uses the C source files for compilation, whereas it just uses 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 DSO. For instance, with .Xr cc 1 just use .Fl fpic . For other C compilers, please consult their manual pages or watch for the flags .Nm uses to compile the object files. .Pp For more details about DSO support in Apache, first read the background information about DSO in .Pa htdocs/manual/dso.html , then read the documentation of .Ic mod_so . .Pp The options are as follows: .Bl -tag -width Ds .It Fl A Same as the .Fl a option but the created .Ic LoadModule directive is prefixed with a hash sign (#), i.e. the module is just prepared for later activation but initially disabled. .It Fl a This activates the module by automatically adding a corresponding .Ic LoadModule line to Apache's httpd.conf configuration file, or by enabling it if it already exists. .It Fl c Compile. This option first compiles the C source files (.c) of .Ar file ...\& into corresponding object files (.o) and then builds a DSO in .Ar dsofile by linking these object files plus the remaining object files (.o and .a) of .Ar file ... If no .Fl o option is specified, the output file is guessed from the first filename in .Ar file ...\& and thus usually defaults to .No mod_ Ns Ar name Ns \&.so .It Xo .Fl D .Ar variable Ns Op = Ns Ar value .Xc This option is directly passed through to the compilation command(s). Use this to add your own defines to the build process. .It Fl e Edit. This option can be used with the .Fl a and .Fl A options to edit the configuration file, .Pa /var/www/conf/httpd.conf , without attempting to install the module. .It Fl g Template generation. This option generates a subdirectory .Ar name (see the .Fl n option) and two files: a sample module source file named .No mod_ Ns Ar name Ns \&.c , which can be used as a template for creating your own modules or as a quick start for playing with the .Nm mechanism, and a corresponding .Pa Makefile for even easier building and installing of this module. .It Fl I Ar incdir 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. .It Fl i Install. This option installs one or more DSOs into the server's .Ar libexec directory. .It Fl L Ar libdir This option is directly passed through to the linker command. Use this to add your own library directories to search to the build process. .It Fl l Ar libname This option is directly passed through to the linker command. Use this to add your own libraries to search to the build process. .It Fl n Ar name This explicitly sets the module name for the .Fl i (install) and .Fl g (template generation) option. Use this to explicitly specify the module name. For option .Fl g this is required; for option .Fl i , .Nm tries to determine the name from the source or (as a fallback) at least by guessing it from the filename. .It Fl o Ar dsofile Explicitly specifies the filename of the created DSO file. If not specified and the name cannot be guessed from the .Ar file ...\& list, the fallback name .Ar mod_unknown.so is used. .It Fl q Query. This option performs a query for .Nm apxs Ns 's knowledge about certain settings. The .Ar query parameters can be one or more of the following variable names: .Bd -literal -offset indent CC TARGET CFLAGS SBINDIR CFLAGS_SHLIB INCLUDEDIR LD_SHLIB LIBEXECDIR LDFLAGS_SHLIB SYSCONFDIR LIBS_SHLIB PREFIX .Ed .Pp Use this for manually determining settings. For instance, use the following inside your own Makefiles if you need manual access to Apache's C header files: .Pp .Dl INC=-I`apxs -q INCLUDEDIR` .It Fl S Ar variable Ns = Ns Ar value This option changes the .Nm settings described above. .It Fl Wc , Ns Ar compiler-flags This option passes .Ar compiler-flags as additional flags to the compiler command. Use this to add local compiler-specific options. This option may be specified multiple times in order to pass multiple flags. .It Fl Wl , Ns Ar linker-flags This option passes .Ar linker-flags as additional flags to the linker command. Use this to add local linker-specific options. This option may be specified multiple times in order to pass multiple flags. .El .Sh EXAMPLES Assume you have a module named .Dq mod_foo.c available which should extend httpd's functionality. To accomplish this, first compile the C source into a DSO suitable for loading into httpd at runtime via the following command: .Bd -literal -offset indent # apxs -c mod_foo.c cc -O2 -pipe -DDEV_RANDOM=/dev/arandom -DMOD_SSL=208116 -DEAPI -DUSE_EXPAT -I../lib/expat-lite -DUSE_SETUSERCONTEXT -fPIC -DSHARED_MODULE -I/usr/lib/apache/include -c mod_foo.c cc -shared -fPIC -DSHARED_MODULE -o mod_foo.so mod_foo.o .Ed .Pp Then a .Ic LoadModule directive has to be added to httpd's configuration file to load the DSO. To simplify this step, .Nm provides an automatic way to install the DSO in the .Dq libexec directory and update the httpd.conf file accordingly. This can be achieved by running the following: .Bd -literal -offset indent $ apxs -i -a mod_foo.so [activating module `foo' in /var/www/conf/httpd.conf] cp mod_foo.so /usr/lib/apache/modules/mod_foo.so chmod 755 /usr/lib/apache/modules/mod_foo.so cp /var/www/conf/httpd.conf /var/www/conf/httpd.conf.bak cp /var/www/conf/httpd.conf.new /var/www/conf/httpd.conf rm /var/www/conf/httpd.conf.new .Ed .Pp This way a line such as the following is added to the configuration file: .Pp .Dl LoadModule foo_module /usr/lib/apache/modules/mod_foo.so .Pp If you want the module added to the configuration file without it being enabled, use the .Fl A option instead: .Pp .Dl $ apxs -i -A mod_foo.so .Pp For a quick test of the .Nm mechanism, create a sample module template plus a corresponding .Ar Makefile via: .Bd -literal -offset indent # apxs -g -n foo Creating [DIR] foo Creating [FILE] foo/Makefile Creating [FILE] foo/mod_foo.c .Ed .Pp The sample module can then be immediately compiled into a DSO and loaded into the httpd server: .Bd -literal -offset indent $ cd foo $ make all reload apxs -c mod_foo.c cc -O2 -pipe -DDEV_RANDOM=/dev/arandom -DMOD_SSL=208116 -DEAPI -DUSE_EXPAT -I../lib/expat-lite -DUSE_SETUSERCONTEXT -fPIC -DSHARED_MODULE -I/usr/lib/apache/include -c mod_foo.c cc -shared -fPIC -DSHARED_MODULE -o mod_foo.so mod_foo.o apxs -i -a -n 'foo' mod_foo.so [activating module `foo' in /var/www/conf/httpd.conf] cp mod_foo.so /usr/lib/apache/modules/mod_foo.so chmod 755 /usr/lib/apache/modules/mod_foo.so cp /var/www/conf/httpd.conf /var/www/conf/httpd.conf.bak cp /var/www/conf/httpd.conf.new /var/www/conf/httpd.conf rm /var/www/conf/httpd.conf.new apachectl restart /usr/sbin/apachectl restart: httpd not running, trying to start /usr/sbin/apachectl restart: httpd started .Ed .Pp .Nm can even be used to compile complex modules outside the httpd source tree, like PHP3, because .Nm automatically recognizes C source files and object files. .Bd -literal -offset indent $ cd php3 $ ./configure --with-shared-apache=../apache-1.3 $ apxs -c -o libphp3.so mod_php3.c libmodphp3-so.a gcc -fpic -DSHARED_MODULE -I/tmp/apache/include -c mod_php3.c ld -Bshareable -o libphp3.so mod_php3.o libmodphp3-so.a .Ed .Pp Only C source files are compiled, while remaining object files are used for the linking phase. .Sh SEE ALSO .Xr cc 1 , .Xr apachectl 8 , .Xr httpd 8