Apache HTTP Server是Apache軟體基金會的一個開放源碼的網頁伺服器軟體,可以在大多數電腦作業系統中運作。由于其跨平台和安全性,被廣泛使用,是最流行的Web伺服器軟體之一。它快速、可靠并且可通過簡單的API擴充,将Perl/Python等解釋器編譯到伺服器中。
[root@Jaking12 ~]# yum install -y gcc pcre pcre-devel expat-devel bzip2 openssl-devel zlib* libtool
[root@Jaking12 src]# rz
[root@Jaking12 src]# tar xvf apr-1.7.0.tar.gz
[root@Jaking12 src]# ls
apr-1.7.0 apr-1.7.0.tar.gz
[root@Jaking12 src]# cd apr-1.7.0
[root@Jaking12 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@Jaking12 apr-1.7.0]# make
[root@Jaking12 apr-1.7.0]# make install
[root@Jaking12 apr-1.7.0]# cd ..
rz waiting to receive.
zmodem trl+C ȡ
100% 541 KB 541 KB/s 00:00:01 0 Errors..
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
[root@Jaking12 src]# tar xf apr-util-1.6.1.tar.gz
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz
[root@Jaking12 src]# cd apr-util-1.6.1
[root@Jaking12 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@Jaking12 apr-util-1.6.1]# make
[root@Jaking12 apr-util-1.6.1]# make install
更多的選項可以通過./configure --help 了解
官方的編譯選項文檔
http://httpd.apache.org/docs/current/programs/configure.html--prefix=/usr/local/apache
--sysconfdir=/etc/httpd // 指定配置檔案在安裝在哪個路徑。如不指定,配置檔案就在程式安裝的目錄;如指定/etc目錄
--with-apr=/usr/local/apr // 指定依賴的apr路徑。注意必須指明路徑,否則編譯時會自動去找/usr下的apr,而不是編譯的高版本apr,下同
--with-apr-util=/usr/local/apr-util
--with-mpm=MPM //指定預設的 [prefork | worker | event] 如3種MPM子產品都編譯了,則通過此項指定預設使用哪種
--with-pcre //依賴pcre庫用于解決正規表達式問題。 ## 安裝 pcre-devel(相容Perl的正規表達式庫)
--enable-so //打開 so 子產品,啟用動态裝載子產品功能
--enable-ssl //啟用ssl功能。注意要先安裝,https使用
--enable-cgi //啟用cgi功能,為非線程方式工作的mpm使用
--enable-cgid //以線程工作(worker/event)的mpm使用
--enable-rewrite //支援 URL 重寫
--enable-zlib //通用壓縮機制
--enable-module=most //[ all | most | ……] 指定啟用哪些子產品。可指定具體的子產品名,也可使用all表示啟用所有子產品,most表示啟用大多數常用子產品。
一般使用most即可
--enable-mpms-shared=all //啟用MPM支援的模式,啟用哪種mpm(prefork,worker,event),使用worker或event時要另外一種方式編譯php(編譯時使用了–enable-maintainer-zts選項)
--enable-deflate //傳輸壓縮機制,節約帶寬提供對内容的壓縮傳輸編碼支援一般是html、js、css等内容的站點。使用此參數會大大
提高傳輸速度提升通路者通路的體驗。在生産環境中這是apache調優的一個重要選項之一
[root@Jaking12 apr-util-1.6.1]# cd ..
100% 8983 KB 8983 KB/s 00:00:01 0 Errors
apr-1.7.0 apr-1.7.0.tar.gz apr-util-1.6.1 apr-util-1.6.1.tar.gz httpd-2.4.39.tar.gz
[root@Jaking12 src]# tar xf httpd-2.4.39.tar.gz
apr-1.7.0 apr-util-1.6.1 httpd-2.4.39
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.39.tar.gz
[root@Jaking12 src]# cd httpd-2.4.39
[root@Jaking12 httpd-2.4.39]# ./configure --prefix=/usr/local/apache24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event
[root@Jaking12 httpd-2.4.39]# make
[root@Jaking12 httpd-2.4.39]# make install
所有元件 /usr/local/apache24
主配置檔案 /usr/local/apache24/conf
啟動腳本 /usr/local/apache24/bin/apachectl
[root@Jaking12 httpd-2.4.39]# ls /usr/local/apache24/
bin build cgi-bin conf error htdocs icons include logs man manual modules
[root@Jaking12 httpd-2.4.39]# ls /usr/local/apache24/conf/
extra httpd.conf magic mime.types original
[root@Jaking12 httpd-2.4.39]# ls /usr/local/apache24/bin/
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve
apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs
[root@Jaking12 httpd-2.4.39]# ll /usr/local/apache24/bin/apachectl
-rwxr-xr-x 1 root dip 3440 Mar 10 16:45 /usr/local/apache24/bin/apachectl
啟動 apache2.4
[root@Jaking12 httpd-2.4.39]# /usr/local/apache24/bin/apachectl
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::250:56ff:fe2c:fe97%ens33. Set the 'ServerName' directive globally to suppress this message
這是一個提示,問題不大 (⊙o⊙)…
重新開機 apache2.4
[root@Jaking12 httpd-2.4.39]# /usr/local/apache24/bin/apachectl graceful
檢視 apache2.4 相關資訊
[root@Jaking12 httpd-2.4.39]# netstat -pantul | grep 80
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 807/sshd
tcp6 0 0 :::80 :::* LISTEN 35199/httpd
tcp6 0 0 :::22 :::* LISTEN 807/sshd
[root@Jaking12 httpd-2.4.39]# grep DocumentRoot /usr/local/apache24/conf/httpd.conf
DocumentRoot: The directory out of which you will serve your
DocumentRoot "/usr/local/apache24/htdocs"
# access content that does not live under the DocumentRoot.
[root@Jaking12 httpd-2.4.39]# ls /usr/local/apache24/htdocs
index.html
[root@Jaking12 httpd-2.4.39]# cat /usr/local/apache24/htdocs/index.html
It works!
源碼編譯 apache2.4源碼編譯 apache2.4
自定義首頁内容
[root@Jaking12 httpd-2.4.39]# vim /usr/local/apache24/htdocs/index.html
Hello World!
設定檔案共享服務
[root@Jaking12 httpd-2.4.39]# cd /usr/local/apache24/htdocs/
[root@Jaking12 htdocs]# ls
[root@Jaking12 htdocs]# touch file{1..10}
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 index.html
[root@Jaking12 htdocs]# mv index.html index.html.bak
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 index.html.bak
總結
至此,實戰示範源碼編譯 apache2.4完畢。