編譯安裝apache
簡單的編譯安裝步驟如下:以centos7為例
第一步:
準備開發工具包組件:Deve Lopment Tools(可以使用yum install Deven Lopment Tools 安裝);pcre* openssl*
第二部:
從官網下載apache源碼包 tar.bz2 或者 tar.gz 格式 (wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.bz2)下載至當前目錄
使用解壓做命令:tar zxf httpd-2.4.29.tar.bz2
cd進httpd-2.4.29.tar.bz2
第二步:
執行 ./configure之前建議閱讀README與INSTALL文件或者 ./configure --help 查看其支持的功能選項及其參數;生產環境可以根據需要指定功能即可。這裏是測試環境所以我們只需要簡單指定安裝目錄及配置文件的安裝位置;
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/apache2
這裏出現報錯缺少“APR”這個包通常缺的是 -devel的包直接用yum -list “APR*” 然後 yum -y install apr-devel 直接安裝即可;
[root@CentOS7 /app/httpd-2.4.29 139]#./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -pthread"
setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... /usr/bin/pcre-config
configure: Using external PCRE library from /usr/bin/pcre-config
setting PCRE_INCLUDES to ""
setting PCRE_LIBS to "-lpcre"
configure:
configure: Configuring Apache httpd...
configure:
setting INCLUDES to "-I."
adding "-I$(top_srcdir)/os/$(OS_DIR)" to INCLUDES
adding "-I$(top_srcdir)/include" to INCLUDES
adding "-I/usr/include/apr-1" to INCLUDES
configure:
configure: Applying OS-specific hints for httpd...
configure:
forcing SINGLE_LISTEN_UNSERIALIZED_ACCEPT to "1"
forcing AP_NONBLOCK_WHEN_MULTI_LISTEN to "1"
checking for rm... /usr/bin/rm
checking for pkg-config... /usr/bin/pkg-config
checking for rsync... /usr/bin/rsync
config.status: creating docs/conf/extra/httpd-ssl.conf
config.status: creating docs/conf/extra/httpd-userdir.conf
config.status: creating docs/conf/extra/httpd-vhosts.conf
config.status: creating docs/conf/extra/proxy-html.conf
config.status: creating include/ap_config_layout.h
config.status: creating support/apxs
config.status: creating support/apachectl
config.status: creating support/dbmmanage
config.status: creating support/envvars-std
config.status: creating support/log_server_status
config.status: creating support/logresolve.pl
config.status: creating support/phf_abuse_log.cgi
config.status: creating support/split-logfile
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
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.29
Install prefix: /usr/local/apache2
C compiler: gcc -std=gnu99
CFLAGS: -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E(輸出信息太多截取部分檢查安裝環境configure腳本)
第三步:開始編譯 執行 mak
dules -module -avoid-version mod_rewrite.lo
make[4]: Leaving directory `/app/httpd-2.4.29/modules/mappers'
make[3]: Leaving directory `/app/httpd-2.4.29/modules/mappers'
make[2]: Leaving directory `/app/httpd-2.4.29/modules'
make[2]: Entering directory `/app/httpd-2.4.29/support'
make[2]: Leaving directory `/app/httpd-2.4.29/support'
make[1]: Leaving directory `/app/httpd-2.4.29'
輸出信息太多截取部分。這一步沒有提示錯誤接下來可以執行下一條命令
第四步:
makeinstall(這一步基本都是cp文件到各個目錄)
Installing configuration files
mkdir /etc/apache2
mkdir /etc/apache2/extra
mkdir /etc/apache2/original
mkdir /etc/apache2/original/extra
Installing HTML documents
mkdir /usr/local/apache2/htdocs
Installing error documents
mkdir /usr/local/apache2/error
Installing icons
mkdir /usr/local/apache2/icons
mkdir /usr/local/apache2/logs
Installing CGIs
mkdir /usr/local/apache2/cgi-bin
Installing header files
mkdir /usr/local/apache2/include
Installing build system files
mkdir /usr/local/apache2/build
Installing man pages and online manual
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/app/httpd-2.4.29'
編譯安裝基本算是完成;接下來我們需要導出頭文件; 庫文件;PATH環境變量;幫助文件 編譯安裝沒有PATH環境變量bash會無法找到
導出二進制程序目錄至PATH環境變量中:
編輯文件/etc/profile.d/NAME.sh
export PATH=/usr/local/apache2/bin:$PATH(不在配置文件中配置),它僅僅對當前shell進程生效
導出庫文件路徑
編輯/etc/ld.so.conf.d/NAME.conf /usr/local/apache2/lib,添加庫文件路徑到隨便一個文件名.conf中;
然後讓系統重新生成緩存: ldconfig [-v] //-v顯示生成緩存過程
導出頭文件
/usr/local/apache2/include應該放置/usr/include裏面來,創建鏈接就可以實現了,ln -sv,創建符號鏈接
ln –sv
導出幫助手冊編輯/etc/man.config文件
按照相同格式補上路徑即可
第五步:
關閉防火墻:鍵入本機ip就可以測試
啟動服務測試
編譯安裝apache