Apache on Cygwin is configured and compiled the same way as on most Unix systems. Refer to
the general configuration and
installation documents for details.
There are three ways to configure and build Apache for Cygwin, depending on how additional
Apache modules should be used:
- Static linked version
To build a static linked version of httpd including additional modules,
use the following commands in the shell:
$ cd apache_1.3.x
$ ./configure [--enable-module=module|--add-module=/path/to/module]
$ make
This will produce the required extra libraries or object files for module and
link everything to src/httpd.exe.
- Shared core, DLL linked version ('one-for-all' version)
To build a DLL version of httpd including additional modules, use the
following commands:
$ cd apache_1.3.x
$ ./configure --enable-rule=SHARED_CORE \
[--enable-module=module|--add-module=/path/to/module]
$ make
$ make install
This will produce the required extra libraries or object files that hold all static
linked code. Then dllwrap and dlltool will export all of those
(including any additional module code) to the shared cyghttpd.dll and create
the libhttpd.a import library which is required for linking httpd.exe.
Note: After make install is performed you will find the
resulting core DLL module cyghttpd.dll within /usr/local/apache/libexec.
This is due to the installation process. Please move the file to Apache's bin
directory, i.e.
$ mv /usr/local/apache/libexec/cyghttpd.dll /usr/local/apache/bin
or to an other place inside your $PATH, i.e. /usr/bin is used
in the Cygwin Net Distribution layout. The core DLL module cyghttpd.dll is
the only file that should reside in /usr/local/apache/bin directory.
All other shared DLL modules mod_foo.dll should be located in /usr/local/apache/libexec.
- Shared DLL modules linked version
This method is ONLY supported using a version of ld.exe
which supports the --auto-import option. Please see the
requirements
section for more information.
To build a dynamic loadable DLL version of httpd which can load DLL
modules on the fly (at runtime), proceed as follows:
-
First build Apache's shared core as follows:
$ cd apache_1.3.x
$ ./configure --enable-rule=SHARED_CORE --enable-module=so \
[--enable-module=module|--add-module=/path/to/module] \
[--enable-shared=module]
$ make
You will notice that there is a warning message shown which lets you know that the
shared core DLL library src/cyghttpd.dll is missing while trying to link
the shared DLL modules mod_foo.dll.
Unfortunately, during Apache's build process, the shared modules are linked before
the shared core import library src/cyghttpd.dll has been made. The shared
modules depend on this import library, so they cannot link for the first time you run make.
- Re-run
make to build the shared module DLLs and install the whole
package to the installation directory:
$ make
$ make install
All shared modules are placed into libexec, including the shared core
DLL cyghttpd.dll. When Apache's /bin/httpd is started, it
has to dynamically link cyghttpd.dll during runtime; that is why you have
to place the shared core DLL cyghttpd.dll to the same directory where httpd.exe
resides, i.e. /usr/local/apache/bin or an other place in your $PATH.
- Add configuration directives to
conf/httpd.conf to load and activate
shared DLL modules at runtime:
# httpd.conf
[...]
LoadModule foo_module libexec/mod_foo.dll
AddModule mod_foo.c
[...]
- Using
apxs to create shared DLL modules
To make the extending httpd with shared DLL modules easier, you can use
apxs.
Make sure you have configured $CFG_LDFLAGS_SHLIB within apxs
to include the --shared directive and the path to the shared code DLL cyghttpd.dll.
After performing make install you will probably have the following lines
within your apxs:
# apxs
[...]
my $CFG_LD_SHLIB = q(dllwrap --export-all --output-def libhttpd.def --implib libhttpd.a
--driver-name gcc);
# substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = q(-g); # substituted via Makefile.tmpl
my $CFG_LIBS_SHLIB = q(); # substituted via Makefile.tmpl
[...]
Change these to reflect the new compile options needed for shared DLL modules as follows:
# apxs
[...]
my $CFG_LD_SHLIB = q(gcc); # substituted via Makefile.tmpl
my $CFG_LDFLAGS_SHLIB = q(-g --shared); # substituted via Makefile.tmpl
my $CFG_LIBS_SHLIB = q(/path/to/cyghttpd.dll); # substituted via Makefile.tmpl
[...]
Now you should be able to create a shared DLL module from a mod_foo.c
source file with:
$ apxs -c mod_foo.c -o mod_foo.dll
Place the resulting DLL in Apache's libexec directory, so the dlopen()
function within the compiled in mod_so.c module can find and load it at
runtime.
Apache for Cygwin supports an option to use the Win32 native socket calls instead of
Cygwin's POSIX wrappers internally. To use the Win32 native socket calls configure Apache for
Cygwin with the CYGWIN_WINSOCK configuration rule flag as follows:
Using Win32 native socket calls is intended for performance reasons and as a hybrid way to
interact with the underlying native socket implementation.