转自:http://blog.snsgou.com/post-240.html
Apache拥有4层结构,从核心到外层的module。而外层的module可以用通过静态和动态两种方式与Apache共同工作。这也就引入下文的“动态”和“静态”两种编译安装方式:
静态编译:
编译的时候,所有的模块自己编译进 httpd 这个文件中 ,启动Apache的时候这些模块就已经加载进来了,可以直接来使用,而不用再
httpd.conf 中在 LoadModule 来加载,只要在 <ifmodule></ifmodule> 中来配置就可以了。
动态编译:
编译的时候,使用enable-MODULE=shared 或者enable-mods-shared=MODULE来动态编译。 动态显然就不编译到httpd里面去了,启动的时候根本不会加载这个模块, 而是给你一个module.so 文件。你想用,就在httpd.conf中使用 loadmodule 这个语法来加载,这个模块才有效。
区别是:
静态的模块通常在http.conf中用<ifmodule></ifmodule> 来配置,动态的要先loadmoule来加载,然后再<ifmodule></ifmodule>配置。
官方说静态的比动态的在性能方面多5%左右。
相对来说,静态的效率高些,而动态方式配置方面灵活。想想如果编译进去的C这个module你想升级或者去掉,静态方式的就只能重新编译Apache了。
下面这句在Apache源文件夹下运行,可以查看默认情况下Apache都给你装了那些module进去:
1 | ./configure –help | grep
disable |
让Apache日后可以动态编译和加载模块:
如果想让Apache日后可以支持动态编译(DSO)更多的module,需要在初次安装时把so这个模块编译到核心(即,静态编译)。
如果编译中包含任何DSO模块,则mod_so会被自动包含进核心。如果希望核心以后能够装载DSO,但不实际编译任何DSO模块,则需明确指定:
针对apache1.x: --enable-module=so
针对apache2.x: --enable-so=static
Apache模块的类型:
基本(B)模块默认包含,必须明确禁用;
扩展(E)/实验(X)模块默认不包含,必须明确启用。
那么,针对以上这些类型的模块,有以下几种操作方式:
--disable-MODULE
禁用MODULE模块(仅用于基本模块)
--enable-MODULE=shared
将MODULE编译为DSO(可用于所有模块)
--enable-MODULE=static
将MODULE静态连接进核心(仅用于扩展和实验模块)
--enable-mods-shared=MODULE-LIST
将MODULE-LIST中的所有模块都编译成DSO(可用于所有模块)
--enable-modules=MODULE-LIST
将MODULE-LIST静态连接进核心(可用于所有模块)
针对--enable-modules和--enable-mods-shared有两个懒办法就是 most参数和all参数,分别表示“很多的”和“所有”。
例如:
mod_alias是个基本模块,不想安装的话就: --disable-alias
mod_rewrite是个扩展模块,想动态加载它:--enable-rewrite=shared,想静态加载就是:--enable-rewrite=static
想静态编译mod_alias和mod_rewrite:--enable-modules='alias rewrite'
想动态编译mod_alias和mod_rewrite:--enable-mods-shared='alias rewrite'
针对Apache2.2.x的一些例子:
最大化静态安装Apache:
1 | ./configure --prefix=/usr/local/apache --enable-modules=all |
最大化动态安装Apache:
1 | ./configure --prefix=/usr/local/apache --enable-mods-shared=all |
静态安装rewrite、动态安装deflate以及headers
1 | ./configure --prefix=/usr/local/apache --enable-rewrite=static --enable-deflate=shared
--enable-headers=shared |
不安装基本的alais,保留以后的扩展DSO能力:
1 | ./configure --prefix=/usr/local/apache --enable-so=static --disable-alias |
在Apache的源码目录,运行命令 ./configure -help 可查看所有编译参数解释
002 | [root@localhost httpd-2.2.22] |
003 | `configure' configures this package to adapt to many kinds of systems. |
005 | Usage: ./configure [OPTION]... [VAR=VALUE]... |
007 | To assign environment variables (e.g., CC, CFLAGS...), specify them as |
008 | VAR=VALUE. See below for
descriptions of some of the useful variables. |
010 | Defaults for
the options are specified in
brackets. |
013 | -h, --help display this help and
exit |
014 | --help=short display options specific to this package |
015 | --help=recursive display the short help of all the included packages |
016 | -V, --version display version information and
exit |
017 | -q, --quiet, --silent
do not print `checking...' messages |
018 | --cache-file=FILE cache
test results in
FILE [disabled] |
019 | -C, --config-cache
alias for
`--cache-file=config.cache' |
020 | -n, --no-create
do not create output files |
021 | --srcdir=DIR
find the sources
in DIR [configure dir
or `..'] |
023 | Installation directories: |
024 | --prefix=PREFIX
install architecture-independent files
in PREFIX |
026 | --exec-prefix=EPREFIX
install architecture-dependent files
in EPREFIX |
029 | By default, `make
install' will install
all the files in |
030 | `/usr/local/apache2/bin', `/usr/local/apache2/lib'
etc. You can specify |
031 | an installation prefix other than `/usr/local/apache2' using `--prefix', |
032 | for instance `--prefix=$HOME'. |
034 | For better control, use the options below. |
036 | Fine tuning of the installation directories: |
037 | --bindir=DIR user executables [EPREFIX/bin] |
038 | --sbindir=DIR system admin executables [EPREFIX/sbin] |
039 | --libexecdir=DIR program executables [EPREFIX/libexec] |
040 | --sysconfdir=DIR
read-only single-machine data [PREFIX/etc] |
041 | --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] |
042 | --localstatedir=DIR modifiable single-machine data [PREFIX/var] |
043 | --libdir=DIR object code libraries [EPREFIX/lib] |
044 | --includedir=DIR C header files [PREFIX/include] |
045 | --oldincludedir=DIR C header files
for non-gcc [/usr/include] |
046 | --datarootdir=DIR
read-only arch.-independent data root [PREFIX/share] |
047 | --datadir=DIR
read-only architecture-independent data [DATAROOTDIR] |
048 | --infodir=DIR info documentation [DATAROOTDIR/info] |
049 | --localedir=DIR locale-dependent data [DATAROOTDIR/locale] |
050 | --mandir=DIR
man documentation [DATAROOTDIR/man] |
051 | --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] |
052 | --htmldir=DIR html documentation [DOCDIR] |
053 | --dvidir=DIR dvi documentation [DOCDIR] |
054 | --pdfdir=DIR pdf documentation [DOCDIR] |
055 | --psdir=DIR
ps documentation [DOCDIR] |
058 | --build=BUILD configure
for building on BUILD [guessed] |
059 | --host=HOST cross-compile to build programs to run on HOST [BUILD] |
060 | --target=TARGET configure
for building compilers
for TARGET [HOST] |
063 | --disable-option-checking ignore unrecognized --enable/--with options |
064 | --disable-FEATURE
do not include FEATURE (same as --enable-FEATURE=no) |
065 | --enable-FEATURE[=ARG] include FEATURE [ARG=yes] |
066 | --enable-layout=LAYOUT |
067 | --enable-v4-mapped Allow IPv6 sockets to handle IPv4 connections |
068 | --enable-exception-hook Enable fatal exception hook |
069 | --enable-maintainer-mode |
070 | Turn on debugging and compile
time warnings |
071 | --enable-pie Build httpd as a Position Independent Executable |
072 | --enable-modules=MODULE-LIST |
073 | Space-separated list of modules to
enable | "all"
| |
075 | --enable-mods-shared=MODULE-LIST |
076 | Space-separated list of shared modules to
enable | |
078 | --disable-authn-file
file-based authentication control |
079 | --enable-authn-dbm DBM-based authentication control |
080 | --enable-authn-anon anonymous user authentication control |
081 | --enable-authn-dbd SQL-based authentication control |
082 | --disable-authn-default authentication backstopper |
083 | --enable-authn-alias
auth provider alias |
084 | --disable-authz-host host-based authorization control |
085 | --disable-authz-groupfile |
086 | 'require group'
authorization control |
087 | --disable-authz-user
'require user' authorization control |
088 | --enable-authz-dbm DBM-based authorization control |
089 | --enable-authz-owner
'require file-owner' authorization control |
090 | --enable-authnz-ldap LDAP based authentication |
091 | --disable-authz-default authorization control backstopper |
092 | --disable-auth-basic basic authentication |
093 | --enable-auth-digest RFC2617 Digest authentication |
094 | --enable-isapi isapi extension support |
095 | --enable-file-cache File cache |
096 | --enable-cache dynamic
file caching |
097 | --enable-disk-cache disk caching module |
098 | --enable-mem-cache memory caching module |
099 | --enable-dbd Apache DBD Framework |
100 | --enable-bucketeer buckets manipulation filter |
101 | --enable-dumpio I/O dump filter |
102 | --enable-echo
ECHO server |
103 | --enable-example example and demo module |
104 | --enable-case-filter example uppercase conversion filter |
105 | --enable-case-filter-in
example uppercase conversion input filter |
106 | --enable-reqtimeout Limit
time waiting for
request from client |
107 | --enable-ext-filter external filter module |
108 | --disable-include Server Side Includes |
109 | --disable-filter Smart Filtering |
110 | --enable-substitute response content rewrite-like filtering |
111 | --disable-charset-lite character
set translation |
112 | --enable-charset-lite character
set translation |
113 | --enable-deflate Deflate transfer encoding support |
114 | --enable-ldap LDAP caching and connection pooling services |
115 | --disable-log-config logging configuration |
116 | --enable-log-forensic forensic logging |
117 | --enable-logio input and output logging |
118 | --disable-env
clearing/setting of ENV vars |
119 | --enable-mime-magic automagically determining MIME
type |
120 | --enable-cern-meta CERN-type
meta files |
121 | --enable-expires Expires header control |
122 | --enable-headers HTTP header control |
123 | --enable-ident RFC 1413 identity check |
124 | --enable-usertrack user-session tracking |
125 | --enable-unique-id
per-request unique ids |
126 | --disable-setenvif basing ENV vars on headers |
127 | --disable-version determining httpd version
in config files |
128 | --enable-proxy Apache proxy module |
129 | --enable-proxy-connect Apache proxy CONNECT module |
130 | --enable-proxy-ftp
Apache proxy FTP module |
131 | --enable-proxy-http Apache proxy HTTP module |
132 | --enable-proxy-scgi Apache proxy SCGI module |
133 | --enable-proxy-ajp Apache proxy AJP module |
134 | --enable-proxy-balancer Apache proxy BALANCER module |
135 | --enable-ssl SSL/TLS support (mod_ssl) |
136 | --enable-distcache Select distcache support
in mod_ssl |
137 | --enable-optional-hook-export |
138 | example optional hook exporter |
139 | --enable-optional-hook-import |
140 | example optional hook importer |
141 | --enable-optional-fn-import |
142 | example optional
function importer |
143 | --enable-optional-fn-export |
144 | example optional
function exporter |
145 | --enable-static-support Build a statically linked version of the support |
147 | --enable-static-htpasswd |
148 | Build a statically linked version of htpasswd |
149 | --enable-static-htdigest |
150 | Build a statically linked version of htdigest |
151 | --enable-static-rotatelogs |
152 | Build a statically linked version of rotatelogs |
153 | --enable-static-logresolve |
154 | Build a statically linked version of logresolve |
155 | --enable-static-htdbm Build a statically linked version of htdbm |
156 | --enable-static-ab Build a statically linked version of ab |
157 | --enable-static-checkgid |
158 | Build a statically linked version of checkgid |
159 | --enable-static-htcacheclean |
160 | Build a statically linked version of htcacheclean |
161 | --enable-static-httxt2dbm |
162 | Build a statically linked version of httxt2dbm |
163 | --enable-http HTTP protocol handling |
164 | --disable-mime mapping of
file-extension to MIME |
165 | --enable-dav WebDAV protocol handling |
166 | --disable-status process/thread monitoring |
167 | --disable-autoindex directory listing |
168 | --disable-asis as-is filetypes |
169 | --enable-info server information |
170 | --enable-suexec
set uid and gid
for spawned processes |
171 | --disable-cgid CGI scripts |
172 | --enable-cgi CGI scripts |
173 | --disable-cgi CGI scripts |
174 | --enable-cgid CGI scripts |
175 | --enable-dav-fs DAV provider
for the filesystem |
176 | --enable-dav-lock DAV provider
for generic locking |
177 | --enable-vhost-alias
mass virtual hosting module |
178 | --disable-negotiation content negotiation |
179 | --disable-dir
directory request handling |
180 | --enable-imagemap server-side imagemaps |
181 | --disable-actions Action triggering on requests |
182 | --enable-speling correct common URL misspellings |
183 | --disable-userdir mapping of requests to user-specific directories |
184 | --disable-alias
mapping of requests to different filesystem parts |
185 | --enable-rewrite rule based URL manipulation |
186 | --enable-so DSO capability |
189 | --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] |
190 | --without-PACKAGE
do not use PACKAGE (same as --with-PACKAGE=no) |
191 | --with-included-apr Use bundled copies of APR/APR-Util |
192 | --with-apr=PATH prefix
for installed APR or the full path to |
194 | --with-apr-util=PATH prefix
for installed APU or the full path to |
196 | --with-pcre=PATH Use external PCRE library |
197 | --with-port=PORT Port on
which to listen (default is 80) |
198 | --with-sslport=SSLPORT Port on
which to securelisten (default is 443) |
199 | --with-z=DIR use a specific zlib library |
200 | --with-sslc=DIR RSA SSL-C SSL/TLS toolkit |
201 | --with-ssl=DIR OpenSSL SSL/TLS toolkit |
202 | --with-mpm=MPM Choose the process model
for Apache to use. |
203 | MPM={beos|event|worker|prefork|mpmt_os2|winnt} |
204 | --with-module=module-type:module-file |
205 | Enable module-file
in the modules/<module-type> |
207 | --with-program-name alternate executable name |
208 | --with-suexec-bin Path to suexec binary |
209 | --with-suexec-caller User allowed to call SuExec |
210 | --with-suexec-userdir User subdirectory |
211 | --with-suexec-docroot SuExec root directory |
212 | --with-suexec-uidmin Minimal allowed UID |
213 | --with-suexec-gidmin Minimal allowed GID |
214 | --with-suexec-logfile Set the logfile |
215 | --with-suexec-safepath Set the safepath |
216 | --with-suexec-umask
umask for
suexec'd process |
218 | Some influential environment variables: |
219 | CC C compiler
command |
220 | CFLAGS C compiler flags |
221 | LDFLAGS linker flags, e.g. -L<lib
dir> if
you have libraries in
a |
222 | nonstandard directory <lib
dir> |
223 | LIBS libraries to pass to the linker, e.g. -l<library> |
224 | CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include
dir> if |
225 | you have headers
in a nonstandard directory <include
dir> |
228 | Use these variables to override the choices made by `configure' or to help |
229 | it to find
libraries and programs with nonstandard names/locations. |
231 | Report bugs to the package provider. |
232 | [root@localhost httpd-2.2.22] |