Skip navigation.

A new Page of Sealinger

Maybe I was a Bird in another Life !

Linux下增加apache的mod_rewrite模块


安装环境:rhel es 4
apache:1.3.37(源码自己编译安装)
gdbm:1.8.3

1. Apache安装rewrite模块的时候需要DBM支持,否则无法编译,表现为:
[nemo@web standard]$ ~/apache/bin/apxs -c mod_rewrite.c
gcc -DLINUX=22 -DHAVE_SET_DUMPABLE -DUSE_HSREGEX -fpic -DSHARED_MODULE -I/home/nemo/apache/include  -c mod_rewrite.c
In file included from mod_rewrite.c:51:
mod_rewrite.h:91:18: ndbm.h: No such file or directory
mod_rewrite.c: In function `lookup_map_dbmfile':
mod_rewrite.c:3035: error: `DBM' undeclared (first use in this function)
mod_rewrite.c:3035: error: (Each undeclared identifier is reported only once
mod_rewrite.c:3035: error: for each function it appears in.)
mod_rewrite.c:3035: error: `dbmfp' undeclared (first use in this function)
mod_rewrite.c:3036: error: `datum' undeclared (first use in this function)
mod_rewrite.c:3036: error: syntax error before "dbmkey"
mod_rewrite.c:3044: error: `dbmkey' undeclared (first use in this function)
mod_rewrite.c:3047: error: `dbmval' undeclared (first use in this function)
apxs:Break: Command failed with rc=1
[nemo@web standard]$ rpm -qa |grep gdbn
[nemo@web standard]$ rpm -qa |grep gdbm
gdbm-1.8.0-24
gdbm-devel-1.8.0-24

所以首先要安装一个GDBM :下载地址:ftp://ftp.gnu.org/gnu/gdbm/
GDBM安装步骤: 进入安装目录,
./configure
make
make install
make install-compat #否则无法编译出ndbm.h头文件.

2. 然后进入到apache源码包解压目录apache_1.3.37/src/modules/standard,用Apache bin目录下的apxs命令安装,注意apxs使用绝对路径:
cd /path/to/apache_1.3.37/src/modules/standard/
/usr/local/apache/bin/apxs -c mod_rewrite.c 
/usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.so

然后在http.conf配置文件里加上:
LoadModule rewrite_module libexec/mod_rewrite.so

接下来用
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl start

停止apache,然后用再start,千万注意,在这里不能用restart或者graceful参数来重新启动apache,必须先停止,然后再开始,否则rewrite将不起作用。

如果你跟我一样的不幸,遇到dbm_fetch错误问题,那么请按我的尝试来操作:

执行完/usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.so后,这个命令已经帮我们复制mod_rewrite.so模块到libexec目录下并且修改好了httpd.conf文件,但测试却出现dbm_fetch错误:
[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Cannot load /home/nemo/apache/libexec/mod_rewrite.so into server: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: dbm_fetch

google一下,马上发现一篇文章写有解决方法(本文最后贴出),继续尝试:
到 apache_1.3.37/src/modules/standard 目录,执行一下这个命令:
gcc -shared -o mod_rewrite.so mod_rewrite.o -lgdbm
cp mod_rewrite.so /usr/local/apache/libexec/

重新检查一下:
[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Can't locate API module structure `mod_rewrite_module' in file /home/nemo/apache/libexec/mod_rewrite.so: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: mod_rewrite_module

修改 httpd.conf ,将
LoadModule mod_rewrite_module libexec/mod_rewrite.so
改为
LoadModule mod_rewrite libexec/mod_rewrite.so

检查一下:
[root@web conf]# ../bin/apachectl configtest
Syntax error on line 16 of /home/nemo/apache/conf/httpd.conf:
Can't locate API module structure `mod_rewrite' in file /home/nemo/apache/libexec/mod_rewrite.so: /home/nemo/apache/libexec/mod_rewrite.so: undefined symbol: mod_rewrite

靠!再改:
LoadModule rewrite_module libexec/mod_rewrite.so

检查:
[root@web conf]# ../bin/apachectl configtest
Syntax OK

NND,总算搞定了!
[root@web conf]# ../bin/apachectl restart   
../bin/apachectl restart: httpd restarted

-------------------------------------
google到的解决方法:
http://www.vttoth.com/rewrite.htm
Technical Notes: Undefined symbol 'dbm_fetch' with the Apache server

I tried to include in my Apache Web server's configuration the mod_rewrite module, but when I restarted the server, I received an error:
Cannot load /usr/local/apache/libexec/mod_rewrite.so into server:
/usr/local/apache/libexec/mod_rewrite.so: undefined symbol: dbm_fetch

The problem, as it turns out, is that mod_rewrite.so is compiled incorrectly. It should be linked with a dbm library but it isn't.

If you have an up-to-date set of Apache source files, you can easily solve this problem by manually rerunning the last compilation step of this module, using the correct options. When you execute make mod_rewrite.so in the appropriate directory, it performs this final step:
gcc -shared -o mod_rewrite.so mod_rewrite.lo

Rerun gcc, this time adding a reference to the GNU gdbm library:
gcc -shared -o mod_rewrite.so mod_rewrite.lo -lgdbm

Next, copy the newly created mod_rewrite.so over to /usr/local/apache/libexec or wherever your Apache module files are located.

In my case, this was all that was needed to solve the problem. Your mileage may vary.

自由软件基金会正在考虑禁止Novell发行Linux终于解决不能发送邮件到sohu

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies