Linux下增加Apache的rewrite Module

來源:互聯網
上載者:User
最近,項目需要在已經編譯好的Apache上以動態方式載入rewrite模組。於是,我們在網上找了許多資料,但都講解得不是很詳細且格式錯位問題嚴重。所以我們有必要把這一過程再重述一遍。實際操作步驟如下:

工作現場描述:
    Linux 2.4.21
    apache_1.3.34.tar.gz    解壓後的目錄為 /root/apache_1.3.34 文中簡稱為“源碼目錄”
    apache安裝目錄 /usr/local/apache 文中簡稱為“目標目錄”

步驟:
1、Apache安裝rewrite模組的時候需要DBM支援,否則無法編譯,所以首先要安裝一個GDBM 
    :ftp://ftp.gnu.org/gnu/gdbm/
    安裝步驟:
        進入安裝目錄,
        ./configure
        make
        make install
        make install-compat    (最後行也要執行。否則無法編譯出ndbm.h標頭檔)
    如果您不能確定伺服器上是否已經裝有DBM,那麼可以安裝一下。否則這步可以跳過。

2、現在到apache源碼目錄的標準模組目錄中(/root/apache_src/src/modules/standard/)中,使用如下指令編譯出so檔案:
    /usr/local/apache/bin/apxs -c mod_rewrite.c -lgdbm
  即可得到mod_rewrite.so檔案。
    備忘:"-lgdbm"是用為說明在編譯mod_rewrite.c時要把gdbm連結進來。這樣在第6步啟動apache時就不會報出"dbm fetch"的錯誤了。

3、現在讓apache的apxs來自動向http.conf設定檔中加入LoadModule語句並將mod_rewrite.so檔案拷貝到apache/libexec目錄
    /usr/local/apache/bin/apxs -i -A -n rewrite /root/apache_1.3.34/src/modules/standard/mod_rewrite.so
    備忘:命令中的rewrite參數是告訴apxs命令mod_rewrite.so檔案中的模組名。在命令執行後,apxs會在LoadModule中為rewrite加上"_module"以標名模組名稱。如果你在啟動apache時發現總是給出“不能定位API”之類的錯誤,那就是說明LoadModule後面的模組名的文法要根據您的apache版本加以改變。

4、停止apache
    apache/bin/apachectl stop

5、回合組態檔案檢查命令
    apache/bin/apachectl configtest
    如顯示Syntax OK,則表示整個操作成功。那麼可以到第6步。否則根據提示資訊進行調試。但只要按照此文所說進行操作是不會出錯的。

6、啟動apache
    apache/bin/apachectl start

全文結束。

參考原文
============================

公司一台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.

轉自:http://www.phpchina.cn/bbs/viewthread.php?tid=96 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.