/****源文件安裝過程演示****/linux
(1)運行httpd-2.4.12中的configure文件apache
[root@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewritevim
checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation. # 報錯了,提示須要APR
(2)安裝依賴包APR緩存
(A)能夠從Apache網站上下載一個APR包,經過filezilla上傳到Linux機器上,並安裝這個程序包:bash
[root@localhost bin_src]# ll服務器
total 5624 -rw-r--r--. 1 root root 694427 Aug 17 18:58 apr-util-1.5.4.tar.bz2 drwxr-xr-x. 11 user2 games 4096 Aug 17 18:54 httpd-2.4.12 -rw-r--r--. 1 root root 5054838 Aug 17 17:51 httpd-2.4.12.tar.bz2
[root@localhost bin_src]# tar xf apr-1.5.1.tar.bz2 cookie
[root@localhost bin_src]# cd apr-1.5.1session
[root@localhost apr-1.5.1]# lsless
apr-config.in build configure.in libapr.dep memory random threadproc apr.dep buildconf docs libapr.dsp misc README time apr.dsp build.conf dso libapr.mak mmap READMENaNake tools apr.dsw build-outputs.mk emacs-mode libapr.rc network_io shmem user apr.mak CHANGES encoding LICENSE NOTICE strings apr.pc.in CMakeLists.txt file_io locks NWGNUmakefile support apr.spec config.layout helpers Makefile.in passwd tables atomic configure include Makefile.win poll test
(B)首先來查看一下APR包的安裝文檔:dom
[root@localhost apr-1.5.1]# cat README
Apache Portable Runtime Library (APR) ------------------------------------- The Apache Portable Runtime Library provides a predictable and consistent interface to underlying platform-specific ... Configuring and Building APR on Unix ==================================== Simply; ./configure --prefix=/desired/path/of/apr make make test make install Configure has additional options, ./configure --help will offer you ... Generating Test Coverage information with gcc ============================================= If you want to generate test coverage data, use the following steps: ./buildconf CFLAGS="-fprofile-arcs -ftest-coverage" ./configure make cd test make ./testall cd .. make gcov
(C)如今來運行configure腳本
[root@localhost apr-1.5.1]# ./configure --prefix=/usr/local/apr
checking langinfo.h usability... yes ... config.status: executing default commands
[root@localhost apr-1.5.1]# ls
apr-1-config atomic config.nice helpers Makefile passwd test apr-config.in build config.status include Makefile.in poll threadproc ... apr.pc CMakeLists.txt emacs-mode libtool network_io strings apr.pc.in config.layout encoding LICENSE NOTICE support apr.spec config.log file_io locks NWGNUmakefile tables # 運行 ./configure腳本後發現該目錄中多了一些文件
(D)執行make命令
這一步不須要任何參數,由於默認參數是gcc,這也是比較經常使用的編譯器。
make文件會使用到Makefile,這是個文本文件,能夠查看一下該文件:
[root@localhost apr-1.5.1]# file Makefile
Makefile: ASCII English text
[root@localhost apr-1.5.1]# less Makefile
srcdir=. top_srcdir=/yum/bin_src/apr-1.5.1 top_blddir=/yum/bin_src/apr-1.5.1 ... prefix=/usr/local/apr exec_prefix=${prefix} bindir=${exec_prefix}/bin libdir=${exec_prefix}/lib includedir=${prefix}/include/apr-${APR_MAJOR_VERSION} installbuilddir=${prefix}/build-1 ... # Macros for target determination
[root@localhost apr-1.5.1]# make
... sed 's,^\(location=\).*$,\1installed,' < apr-1-config > apr-config.out sed -e 's,^\(apr_build.*=\).*$,\1/usr/local/apr/build-1,' -e 's,^\(top_build.*=\).*$,\1/usr/local/apr/build-1,' < build/apr_rules.mk > build/apr_rules.out make[1]: Leaving directory `/yum/bin_src/apr-1.5.1' # 這個過程是自動完成的, leaving directory表示編譯完成
(E)執行make install命令
[root@localhost apr-1.5.1]# make install
/yum/bin_src/apr-1.5.1/build/mkdir.sh tools /bin/sh /yum/bin_src/apr-1.5.1/libtool --silent --mode=compile gcc -g -O2 -pthread ... mkdir /usr/local/apr # 程序包的根目錄 mkdir /usr/local/apr/lib # 程序包的庫目錄 mkdir /usr/local/apr/bin # 程序包生成的二進制碼 mkdir /usr/local/apr/build-1 mkdir /usr/local/apr/lib/pkgconfig mkdir /usr/local/apr/include mkdir /usr/local/apr/include/apr-1 ... for f in make_exports.awk make_var_export.awk; do \ /usr/bin/install -c -m 644 /yum/bin_src/apr-1.5.1/build/${f} /usr/local/apr/build-1; \ done /usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk /usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
(3)安裝apache服務器
(A)解決依賴關係
解決了APR包的依賴關係,如今能夠編譯安裝apache服務器了,仍是遵循上述步驟:
[root@localhost bin_src]# cd httpd-2.4.12
[root@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite
checking for APR-util... no configure: error: APR-util not found. Please read the documentation. ... checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
此次提示沒有APR-util,能夠重複上述安裝APR包的方法安裝APR-util以及另外一個依賴包PCRE。
當APR, APR-util和PCRE依賴包都解決後,安裝apache時可能須要加上 --with-apr=/usr/local/apr,--with-apr-util=/usr/local/apr-util/ 和 --with-pcre=/usr/local/pcre來指定依賴包的路徑
(B)執行./configure腳本
[root@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --with-pcre=/usr/local/bin/pcre-config
# pcre使用的默認安裝,故pcre-congfig路徑如上 config.status: creating build/rules.mk ... config.status: executing default commands
(C)執行make和make install命令
[root@localhost httpd-2.4.12]# make
dules/database -I/yum/bin_src/httpd-2.4.12/modules/filters -I/yum/bin_src/httpd-2.4.12/modules/ldap ... make[1]: Leaving directory `/yum/bin_src/httpd-2.4.12' [root@localhost httpd-2.4.12]# make install ... mkdir /usr/local/apache/manual make[1]: Leaving directory `/yum/bin_src/httpd-2.4.12'
[root@localhost httpd-2.4.12]# cd /usr/local/apache
[root@localhost apache]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules # 能夠看到成功建立了不少目錄
(D)啓動apache服務器
[root@localhost apache]# cd bin
[root@localhost bin]# ls
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs
[root@localhost apache]# ls include
# .h結尾的多爲頭文件 apache_noprobes.h ap_release.h http_vhost.h mod_so.h util_ebcdic.h ap_compat.h ap_slotmem.h mod_auth.h mod_ssl.h util_fcgi.h ap_config_auto.h ap_socache.h mod_cache.h mod_status.h util_filter.h ap_config.h cache_common.h mod_cgi.h mod_unixd.h util_ldap.h
[root@localhost apache]# ls conf
extra httpd.conf magic mime.types original # httpd.conf是apache的主配置文件,httpd是apache服務器的主程序,而執行腳本apachectl,加上start選項,能夠啓動該服務器
[root@localhost apache]# apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName # 這裏提示服務器確實start了,但不是啓動的剛纔安裝的服務器,由於系統默認安裝了rpm包的apache服務器。
[root@localhost apache]# hash
hits command 1 /usr/sbin/apachectl # 這是系統默認的apachectl命令 7 /bin/ls
[root@localhost apache]# bin/apachectl start
# 經過全路徑啓動剛纔安裝的服務器,仍然提示命令名稱模糊 AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down # 80端口被系統原來的apache服務器佔用了 AH00015: Unable to open logs
(E)修改服務器的監聽端口
[root@localhost apache]# vim conf/httpd.conf
#Listen 12.34.56.78:80 #Listen 80 Listen 8889 # # Dynamic Shared Object (DSO) Support
(F)再次啓動服務器
[root@localhost apache]# bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message # 此次沒有報服務器端口占用的錯誤了
[root@localhost apache]# netstat -tnlp
# netstat命令能夠查看系統上目前正在被監聽的端口
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1338/rpcbind tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1609/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1425/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1689/master tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2379/sshd tcp 0 0 0.0.0.0:50409 0.0.0.0:* LISTEN 1385/rpc.statd tcp 0 0 :::50764 :::* LISTEN 1385/rpc.statd tcp 0 0 :::111 :::* LISTEN 1338/rpcbind tcp 0 0 :::80 :::* LISTEN 2438/httpd # 系統自帶的服務器端口 tcp 0 0 :::22 :::* LISTEN 1609/sshd tcp 0 0 ::1:631 :::* LISTEN 1425/cupsd tcp 0 0 :::8889 :::* LISTEN 2512/httpd # 新安裝的服務器監聽端口 tcp 0 0 ::1:25 :::* LISTEN 1689/master tcp 0 0 ::1:6010 :::* LISTEN 2379/sshd
能夠看到服務器正常工做了。
(4)額外步驟
(A) 配置服務器啓動命令的環境變量
在實際生產環境中,在程序包的編譯安裝完成後,可能須要配置環境變量(PATH /usr/local/apache/bin, PATH /usr/local/apache/sbin),不然只能全路徑來使用該程序,而使用全路徑來執行服務器啓動命令很不方便,所以能夠建立一個配置文件,爲服務器的啓動命令配置環境變量:
[root@localhost apache]# vim /etc/profile.d/apache.sh
export PATH=/usr/local/apache/bin:$PATH
該文件不會立刻生效,須要從新登陸,或者使用source命令來使其生效:
[root@localhost apache]# . /etc/profile.d/apache.sh
[root@localhost apache]# echo $PATH
/usr/local/apache/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
再使用hash命令查看一下當前啓動的服務器
[root@localhost apache]# help hash
hash: hash [-lr] [-p pathname] [-dt] [name ...] Remember or display program locations. Determine and remember the full pathname of each command NAME. If no arguments are given, information about remembered commands is displayed. Options: -d forget the remembered location of each NAME -l display in a format that may be reused as input -p pathname use PATHNAME is the full pathname of NAME -r forget all remembered locations -t print the remembered location of each NAME, preceding each location with the corresponding NAME if multiple NAMEs are given Arguments: NAME Each NAME is searched for in $PATH and added to the list of remembered commands. Exit Status: Returns success unless NAME is not found or an invalid option is given.
[root@localhost apache]# hash -d
hash: hash table empty
[root@localhost apache]# hash
hash: hash table empty
[root@localhost apache]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost apache]# apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message # 再次啓動服務器
[root@localhost apache]# hash
hits command 2 /usr/local/apache/bin/apachectl # 因爲手動安裝的apache服務器路徑被放在了系統默認的服務器前面,所以默認啓動該服務器
(B)添加庫目錄的搜索路徑
除了修改默認啓動的命令,有可能須要導出軟件包的庫目錄搜索路徑,經過編輯/etc/ld.so.conf,或者新建/etc/ld.so.conf.d/*.conf, 加入庫目錄的路徑。可使用ldd命令來查看某一個程序依賴的庫:
[root@localhost apr-1.5.1]# ldd /bin/ls
# 查看ls命令依賴的庫 linux-vdso.so.1 => (0x00007fff149ff000) libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003c63000000) librt.so.1 => /lib64/librt.so.1 (0x0000003c62800000) libcap.so.2 => /lib64/libcap.so.2 (0x0000003c65000000) libacl.so.1 => /lib64/libacl.so.1 (0x0000003c6e800000) libc.so.6 => /lib64/libc.so.6 (0x0000003c61800000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003c61400000) /lib64/ld-linux-x86-64.so.2 (0x0000003c61000000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003c61c00000) libattr.so.1 => /lib64/libattr.so.1 (0x0000003c6ce00000)
使用ldconfig -v 命令能夠從新搜索當前系統上全部庫文件搜索路徑下的庫文件,並生產緩存/etc/
[root@localhost apache]# ldconfig -v | grep /usr/local/apache
# 不包含手動的庫目錄
[root@localhost apache]# vim /etc/ld.so.conf.d/apache.conf
/usr/local/apache/lib # 編輯配置文件
[root@localhost apache]# ldconfig -v | grep /usr/local/apache
/usr/local/apache/lib:
(C)添加man命令的搜索路徑
[root@localhost apache]# man -M /usr/local/apache/man httpd
# man命令指定httpd的全路徑,比較麻煩,每次開新的終端都須要手動鍵入路徑 ... -w Keep the console window open on error so that the error message can be read. Apache HTTP Server 2012-02-10 HTTPD(8)
若是想使用man命令直接加上httpd,則須要編輯/etc/man/config文件,加入 MANPATH=/usr/local/apache/man;
[root@localhost apache]# ls man
man1 man8
[root@localhost apache]# vim /etc/man.config
# Every automatically generated MANPATH includes these fields # MANPATH /usr/local/apache/man MANPATH /usr/man MANPATH /usr/share/man
[root@localhost apache]# man httpd
# 檢驗是否成功加入 ... -w Keep the console window open on error so that the error message can be read. Apache HTTP Server 2012-02-10 HTTPD(8)
(D)爲頭文件建立連接
/usr/include下有不少頭文件,爲了對剛纔安裝的服務器的頭文件加以區分,建議爲其建立一個連接
[root@localhost apache]# ls /usr/include
aio.h eti.h jmorecfg.h ncurses QtCore string.h aliases.h etip.h jpeglib.h ncurses_dll.h QtDBus strings.h ... error.h jconfig.h mtd Qt3Support stdio.h zconf.h et jerror.h nc_tparm.h QtAssistant stdlib.h zlib.h
[root@localhost apache]# ln -sv /usr/local/apache/include /usr/include/httpd
`/usr/include/httpd' -> `/usr/local/apache/include'
[root@localhost apache]# ls /usr/include
aio.h etip.h jpeglib.h ncurses.h QtGui sysexits.h ... elf.h httpd mntent.h pwd.h stdint.h Xm # 新建立的頭文件目錄連接 ... eti.h jmorecfg.h ncurses_dll.h QtDesigner syscall.h
[root@localhost apache]# ls include
apache_noprobes.h ap_release.h http_vhost.h mod_so.h util_ebcdic.h ... ap_regkey.h http_request.h mod_session.h util_cookies.h
[root@localhost apache]# cd /usr/include/httpd
[root@localhost httpd]# ls
apache_noprobes.h ap_release.h http_vhost.h mod_so.h util_ebcdic.h ... ap_regkey.h http_request.h mod_session.h util_cookies.h