apache安裝擴充模組

來源:互聯網
上載者:User

標籤:

apache 安裝擴充模組

1,首先要確認你是否載入了mod_so模組,這個就是你在編譯前參數配置的時候添加-enable-so(啟用DSO)。如果你沒有這模組的話,是無法安裝擴充模組的。

/usr/local/apache2/bin/apachectl -l  在列出來的內容如果有mod_so,則說明已經添加了載入該模組了。

 

2,安裝擴充模組用到的工具就是apxs, 以安裝mod_status.so這個模組為例。

 

3,cd到apache源碼中,找到對應的C檔案。

cd /usr/local/src/httpd-2.2.31/modules/generators/

這裡我們可以看到mod_status.c這個就是我們需要的檔案。

4,編譯這個模組

 /usr/local/apache2/bin/apxs  -i -a  -c  mod_status.c

這個時候有報錯資訊

-bash: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: 沒有那個檔案或目錄(錯誤的解譯器)

soga  apxs是一個perl的指令碼,我們系統又沒有安裝perl解譯器,所以yum install -y perl並且vi /usr/local/apache2/bin/apxs 將第一行改為perl解譯器的路徑,即#!/usr/bin/perl即可。

這個時候在編譯

/usr/local/apache2/bin/apxs -i -a -c mod_status.c
/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_status.lo mod_status.c && touch mod_status.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_status.la -rpath /usr/local/apache2/modules -module -avoid-version mod_status.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL=‘/usr/local/apache2/build/libtool‘ mod_status.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_status.la /usr/local/apache2/modules/
cp .libs/mod_status.so /usr/local/apache2/modules/mod_status.so
cp .libs/mod_status.lai /usr/local/apache2/modules/mod_status.la
cp .libs/mod_status.a /usr/local/apache2/modules/mod_status.a
chmod 644 /usr/local/apache2/modules/mod_status.a
ranlib /usr/local/apache2/modules/mod_status.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR‘
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH‘ environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH‘ environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR‘ linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf‘

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_status.so

可以看到,已經在modules目錄下產生了mod_status.so這個模組了。

5,查看模組是否載入成功。

/usr/local/apache2/bin/apachectl -M 

發現報錯資訊:

httpd: Syntax error on line 58 of /usr/local/apache2/conf/httpd.conf: module status_module is built-in and can‘t be loaded 

查詢資料,

原來我們原先就已經靜態編譯載入過mod_status.so這個模組,所以我們還是在httpd.con將這個配置注釋掉吧。

 

二,介於上述找的模組並不是很好,所以決定重新安裝另外一個apache擴充模組,以mod_proxy模組為例吧。

1,cd 到源碼包中 

cd /usr/local/src/httpd-2.2.31/modules

cd proxy

可以看到mod_proxy.c這個檔案

 

2,編譯安裝

/usr/local/apache2/bin/apxs -i -c -a mod_proxy.c

/usr/local/apache2/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_proxy.lo mod_proxy.c && touch mod_proxy.slo
/usr/local/apache2/build/libtool --silent --mode=link gcc -o mod_proxy.la -rpath /usr/local/apache2/modules -module -avoid-version mod_proxy.lo
/usr/local/apache2/build/instdso.sh SH_LIBTOOL=‘/usr/local/apache2/build/libtool‘ mod_proxy.la /usr/local/apache2/modules
/usr/local/apache2/build/libtool --mode=install cp mod_proxy.la /usr/local/apache2/modules/
cp .libs/mod_proxy.so /usr/local/apache2/modules/mod_proxy.so
cp .libs/mod_proxy.lai /usr/local/apache2/modules/mod_proxy.la
cp .libs/mod_proxy.a /usr/local/apache2/modules/mod_proxy.a
chmod 644 /usr/local/apache2/modules/mod_proxy.a
ranlib /usr/local/apache2/modules/mod_proxy.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/apache2/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR‘
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH‘ environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH‘ environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR‘ linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf‘

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache2/modules/mod_proxy.so
[activating module `proxy‘ in /usr/local/apache2/conf/httpd.conf]

可以看到模組已經安裝成功。

3,查看是否可以成功載入

/usr/local/apache2/bin/apachectl -M

httpd: Syntax error on line 59 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/mod_proxy.so into server: /usr/local/apache2/modules/mod_proxy.so: undefined symbol: ap_proxy_lb_workers

怎麼又報錯,我也是醉了。。。。。

原來這個proxy模組是需要2個檔案編譯而成的。

重新編譯

/usr/local/apache2/bin/apxs -i -c -a mod_proxy.c  proxy_util.c

可以看到成功了,不對,我們還是看能否真正的載入吧。

/usr/local/apach2/bin/apachectl -M

 

 終於看到了這個模組的存在,這說明擴充安裝成功了。

 

 最後說明一下:/usr/local/apache2/bin/apxs - i -c -a 的中參數的意思。

-c  編譯的意思

- i  安裝的意思

-a  在設定檔中自動添加IfModule資訊。

 

 

 

 

 

 

 

 

 

 

 

 

apache安裝擴充模組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.