apache安裝擴展模塊


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信息。

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM