1. 程式人生 > >Centos7原始碼安裝httpd2.4版本web伺服器

Centos7原始碼安裝httpd2.4版本web伺服器

我們的系統平臺是在centos7.5的環境下安裝httpd2.4版本的軟體,2.4版本的軟體有一個特徵就是需要安裝arp包以及arp-util包才可以。

1、首先是下載httpd2.4版本的包,以及安裝開發環境,這裡開發環境直接使用組安裝“Development tools”即可,(注意centos6是安裝“Development tools和Server Platform Development”兩種開發環境)

wget http://ftp.cuhk.edu.hk/pub/packages/apache.org//httpd/httpd-2.4.37.tar.gz
yum groupinstall "
Development tools"

2、解壓到指定目錄/usr/local目錄下

tar -zxf httpd-2.4.37.tar.gz -C /usr/local

3、在/usr/local目錄下建立一個httpd目錄,然後在剛剛解壓的目錄裡面開始執行configure檢測依賴環境

./configure --prefix=/usr/local/httpd

發現報錯:

configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for
APR-util... no configure: error: APR-util not found. Please read the documentation. configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation.

缺少apr-util包和apr包,那我們來安裝即可

yum install apr apr-util apr-devel apr-util-devel

這兩個包很重要,所以大家一定要記住。也有的人是下載apr原始碼包編譯的,都是可以的。

4、繼續執行configure檢測環境

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd-2.4.37]#./configure --prefix=/usr/local/httpd
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:

    Server Version: 2.4.37
    Install prefix: /usr/local/httpd
    C compiler:     gcc
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

哈哈,終於編譯成功了,繼續安裝

5、接下來執行make命令完成專案構建

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd-2.4.37]#make
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc  -pthread           -o mod_rewrite.la -rpath /usr/local/httpd/modules -module -avoid-version  mod_rewrite.lo 
make[4]: Leaving directory `/usr/local/httpd-2.4.37/modules/mappers'
make[3]: Leaving directory `/usr/local/httpd-2.4.37/modules/mappers'
make[2]: Leaving directory `/usr/local/httpd-2.4.37/modules'
make[2]: Entering directory `/usr/local/httpd-2.4.37/support'
make[2]: Leaving directory `/usr/local/httpd-2.4.37/support'

make[1]: Leaving directory `/usr/local/httpd-2.4.37'

看到這裡說明編譯成功了。

6、執行make install 安裝

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd-2.4.37]#make install
Installing man pages and online manual
mkdir /usr/local/httpd/man
mkdir /usr/local/httpd/man/man1
mkdir /usr/local/httpd/man/man8
mkdir /usr/local/httpd/manual
make[1]: Leaving directory `/usr/local/httpd-2.4.37'

安裝成功。

7、看下安裝的目錄

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local]#cd httpd
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd]#ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd]#cd bin
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/bin]#ls
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/bin]#

8、我們看到了安裝的目錄裡面有我們想要的檔案,但是到這裡還沒有完成,我們還有一些後續工作需要做。

9、設定環境變數

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/bin]#cd /etc/profile.d/
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/profile.d]#ls
256term.csh  colorgrep.csh  colorls.csh  csh.local  lang.sh   less.sh  sh.local  vim.sh      which2.sh
256term.sh   colorgrep.sh   colorls.sh   lang.csh   less.csh  path.sh  vim.csh   which2.csh
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/profile.d]#vim httpd.sh
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/profile.d]#cat httpd.sh 
HTTPD_HOME=/usr/local/httpd
PATH=$PATH:$HTTPD_HOME/bin

最後記得source一下立即生效。

10、建立庫檔案資訊(以.so結尾的檔案)

一般上我們執行程式,Linux系統會在特定的路徑下為應用查詢所以來的庫檔案:/usr/lib、/usr/lib64、/lib、/lib64這四個目錄下面,但是自己編譯安裝的程式提供的庫檔案有可能不在系統搜尋的路徑中,因此我們需要在系統裡面新增一下。注意以.conf結尾。

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/modules]#cd /etc/ld.so.conf.d/
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/ld.so.conf.d]#ls
dyninst-x86_64.conf  kernel-3.10.0-862.3.2.el7.x86_64.conf  mysql-x86_64.conf
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/ld.so.conf.d]#echo /usr/local/httpd/modules > httpd-2.4.37.conf
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/ld.so.conf.d]#cat httpd-2.4.37.conf 
/usr/local/httpd/modules
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/ld.so.conf.d]#

11、然後重新執行ldconfig命令重新生成對映快取ld.so.conf

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /etc/ld.so.conf.d]#ldconfig

12、除了我們剛剛設定的環境變數、庫檔案外,我們還需要設定標頭檔案資訊。我們這裡複製標頭檔案過去即可。

[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/include]#ls
apache_noprobes.h      ap_expr.h      ap_regkey.h        http_core.h      mod_auth.h      util_cookies.h  util_script.h
ap_compat.h            ap_hooks.h     ap_release.h       httpd.h          mod_core.h      util_ebcdic.h   util_time.h
ap_config_auto.h       ap_listen.h    ap_slotmem.h       http_log.h       mod_request.h   util_fcgi.h     util_varbuf.h
ap_config_auto.h.in    ap_mmn.h       ap_socache.h       http_main.h      mpm_common.h    util_filter.h   util_xml.h
ap_config.h            ap_mpm.h       heartbeat.h        http_protocol.h  scoreboard.h    util_ldap.h
ap_config_layout.h     ap_provider.h  http_config.h      http_request.h   util_cfgtree.h  util_md5.h
ap_config_layout.h.in  ap_regex.h     http_connection.h  http_vhost.h     util_charset.h  util_mutex.h
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/include]#mkdir  /usr/include/httpd
[[email protected]:vg_adn_tidbCkhsTest:172.31.30.62 /usr/local/httpd/include]#cp ./*  /usr/include/httpd/

其實我們就是把httpd安裝目錄下的include目錄的所有標頭檔案複製一份,放置在/usr/include/httpd目錄下,注意,這個httpd需要提前建立好。

13、最後就是man手冊了,Centos7下面的man手冊配置檔案是/etc/man_db.conf檔案,我們修改一下即可。