linux服務之apache的源碼安裝(centos)

來源:互聯網
上載者:User

標籤:.so   更新   1.7   報錯   nload   瀏覽器   root   download   com   

  1. 第一部分:前期準備 需要下載的東西  
  2.   
  3. 下載 Apache 源碼包  : http://httpd.apache.org/download.cgi                             我下載的  httpd-2.4.20.tar.gz  
  4.   
  5. 下載 Apr                        :http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz        我下載的是 apr-1.5.0.tar.gz  
  6.   
  7. 下載 Apr-Util               :http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz   我下載的是 apr-util-1.5.4.tar.gz  
  8.   
  9. 注意事項:wget  vim   gcc gcc-c++   cmake  這幾個也是安裝 Apache 所需要的小環境 。有的小環境,一般 Cnetos內建,我個人建議還是手動的再用 yum install  安裝 或者 更新一下。  
  10. 那麼好了,接下來開始安裝吧!  
  11.   
  12. 第一步:解壓下載好的 Apache 包  
  13.   
  14. [[email protected] ~]#   tar -zxvf httpd-2.4.20.tar.gz  
  15.   
  16. //進入目錄  編譯解壓的原檔案  
  17.   
  18. [[email protected] httpd-2.4.20]# ./configure --prefix=/usr/local/apache2/          #配置安裝目錄  
  19.   
  20. 1.正常執行 (說明你的Linux安裝過Apache,或者已經安裝過所需的依賴包)  
  21.   
  22. 2.不正常執行、會出現以下錯誤資訊  
  23.   
  24. configure:  
  25. checking for APR... no  
  26. configure: error: APR not found.  Please read the documentation.  
  27.   
  28. 解決方案:就是安裝 剛剛下載好的 Apr。  Apache在安裝時需要一些準備環境、這裡需要安裝另外一個 Apr(Apache portable runtime)  
  29.   
  30. 第二步:解壓下載好的 Apr 包  
  31.   
  32. [[email protected] ~]#   tar -zxvf apr-1.5.1.tar.gz  
  33.   
  34. //進入目錄  編譯解壓的原檔案  
  35.   
  36. [[email protected] apr-1.5.1]# ./configure --prefix=/usr/local/apr/               #配置安裝目錄  
  37.   
  38. //安裝目錄配置完成  就 make && make install  在指定地址組建目錄和檔案  
  39.   
  40. [[email protected] apr-1.5.1]# make && make install  
  41.   
  42. 第三步:解壓下載好的 Apr-util 包  
  43.   
  44. [[email protected] ~]# tar -zxvf  apr-util-1.5.4.tar.gz  
  45.   
  46. //進入目錄  編譯解壓的原檔案  
  47.   
  48. [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/               #配置安裝目錄  
  49.   
  50. //報錯   看到錯誤資訊   現在自己就知道了吧   --with-apr  
  51.   
  52. [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/  
  53.   
  54. //安裝目錄配置完成  就 make && make install  在指定地址組建目錄和檔案  
  55.   
  56. [[email protected] apr-util-1.5.4]# make && make install  
  57.   
  58. 第四步:繼續安裝 Apache  
  59.   
  60. //切換到 Apache  源檔案  
  61.   
  62. [[email protected] httpd-2.4.20]# ./configure --prefix=/usr/local/apache24/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/  
  63.   
  64. //還會出現下面的錯誤    原因是:還是缺少環境 PCRE  
  65.   
  66. checking for pcre-config... false  
  67. configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/  
  68.   
  69. 解決方案:    http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz       下載最新版本  我下載的是 pcre-8.39.tar.gz  
  70.   
  71. [[email protected] ~]# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz  
  72.   
  73. [[email protected] ~]# tar -zxvf pcre-8.39.tar.gz  
  74.   
  75. [[email protected] pcre-8.39]# ./configure --prefix=/usr/local/pcre/  
  76. [[email protected] pcre-8.39]# make && make install  
  77.   
  78. 第五步:繼續安裝 Apache  
  79.   
  80. [[email protected] httpd-2.4.20]# ./configure --prefix=/usr/local/apache24/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/  
  81. [[email protected] httpd-2.4.20]# make && make install  
  82.   
  83. 第六步:測試 Apache  
  84.   
  85. centos7使用systemctl代替chkconfig管理服務,防火牆也由iptables更換成了firewalld  
  86.   
  87. 首先用systemctl關閉防火牆:  
  88.   
  89. systemctl stop firewalld.service  
  90.   
  91. systemctl disable firewalld.service  
  92.   
  93. 開啟 Apache 服務             停止 stop  
  94.   
  95. [[email protected]~]# cd /usr/local/apache24/bin/  
  96.   
  97. [[email protected] bin]# ./apachectl start  
  98.   
  99. 第七步:在用戶端瀏覽器輸入自己的 IP 地址,看看能夠成功訪問 Apache。  
  100.   
  101. 成功顯示 It Works!就代表 伺服器已成功啟動~\(≧▽≦)/~啦啦啦。  
  102.   
  103. 在自己一步步的操作下,很高心成功啦。也不枉費讀者們耐心的看完! 謝 謝 點 贊!  
  104.   
  105.   
  106.   
  107.   
  108.   
  109.   
  110. 附加: 如果在 安裝 Apache 的時候,使用的是這個命令,則你就可以 進行一下操作了。  
  111.   
  112. ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-cgi --enable-ssl --enable-rewrite --with-ssl=/usr/local/openssl --with-pcre=/usr/local/pcre --with-z=/usr/local/zlib --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl=/usr/local/openssl --enable-modules=most --enable-mpms-shared=all --with-mpm=event  
  113.   
  114.   
  115. 因為安裝Apache伺服器是選擇安裝了支援openssl,順便研究了一下如何在apache中配置openss  
  116.   
  117. 首先在/etc/httpd/http.conf檔案中修改:  
  118.   
  119. ServerName為www.example.com:80  
  120.   
  121. 去掉LoadModule ssl_module modules/mod_ssl.so前的#號  
  122.   
  123. 去掉LoadModule socache_shmcb_module modules/mod_socache_shmcb.so前的#號  
  124.   
  125. 去掉Include /etc/httpd/extra/httpd-ssl.conf前的#號  
  126.   
  127. 產生伺服器憑證:  
  128.   
  129. 1.產生伺服器用的私密金鑰檔案server.key  
  130.   
  131. openssl genrsa -out server.key 1024  
  132.   
  133. 2.產生未簽署的server.csr  
  134.   
  135. openssl req -new -key server.key -out server.csr  
  136.   
  137. 程式提示輸入一系列參數,包括國別、省名、市名。。。,按照提示輸入即可  
  138.   
  139. 3.簽署伺服器憑證檔案server.crt  
  140.   
  141. openssl req -x509 -days 365 -key server.key -in server.csr -out server.crt  
  142.   
  143. 然後將產生的server.key、server.csr、server.crt拷貝到/etc/httpd目錄下  
  144.   
  145. /usr/local/apache/bin/apachectl restart  
  146.   
  147. 瀏覽器訪問:http://192.168.1.75/ 此時瀏覽器會提示安裝認證,安裝後顯示頁面It works!,證明ssl模組已正常工作。

linux服務之apache的源碼安裝(centos)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.