源碼編譯 apache2.4

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 ..
[root@Jaking12 src]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%     541 KB  541 KB/s 00:00:01       0 Errors..

[root@Jaking12 src]# ls
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 
[root@Jaking12 src]# ls
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 ..
[root@Jaking12 src]# rz
rz waiting to receive.
 zmodem trl+C ȡ

  100%    8983 KB 8983 KB/s 00:00:01       0 Errors

[root@Jaking12 src]# ls
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 
[root@Jaking12 src]# ls
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!

 

自定義首頁內容

[root@Jaking12 httpd-2.4.39]# vim /usr/local/apache24/htdocs/index.html
It works!
Hello World!

源碼編譯 apache2.4源碼編譯 apache2.4

設置文件共享服務

[root@Jaking12 httpd-2.4.39]# cd /usr/local/apache24/htdocs/
[root@Jaking12 htdocs]# ls
index.html
[root@Jaking12 htdocs]# touch file{1..10}
[root@Jaking12 htdocs]# ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  index.html
[root@Jaking12 htdocs]# mv index.html index.html.bak
[root@Jaking12 htdocs]# ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  index.html.bak

源碼編譯 apache2.4源碼編譯 apache2.4

總結

至此,實戰演示源碼編譯 apache2.4完畢。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章