公司一台Linux服務器,Apache默認安裝時候沒有加載任何Modules,最近要用到Apache的rewrite模塊,經過一夜一天的努力,終於成功了,興奮....
現在列下幾個要點:
1. Apache安裝rewrite模塊的時候需要DBM支持,否則無法編譯,所以首先要安裝一個GDBM 下載地址:ftp://ftp.gnu.org/gnu/gdbm/
安裝步驟: 進入安裝目錄,./configure; make; make install; make install-compat; 否則無法編譯出ndbm.h頭文件.
2. 然後用Apache bin目錄下的apxs命令安裝
/var/apache/bin/apxs -c mod_rewrite.c {
gcc -DLINUX=22 -DUSE_HSREGEX -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/var/apache/include -c mod_rewrite.c
gcc -shared -o mod_rewrite.so mod_rewrite.o -lgdbm
}
/var/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停止apache,然後用再start,千萬注意,在這裡不能用restart或者graceful參數來重新啟動apache,必須先停止,然後再開始,或者是reboot機器,否則rewrite將不起作用。
-------------------------------------------------------------------------------------------------------------
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.