【只需3步】源碼手動安裝Apache以及配置(親測可行)


作者小波/QQ463431476歡迎轉載!

redhat6采用centos yum源。

第一步下載apache依賴的軟件包並安裝

安裝 apr
下載地址:http://apr.apache.org/download.cgi

 解壓包:tar -jxvf apr-1.5.0.tar.bz2 注意:這里的包的格式是tar.bz2格式,如果是.tar格式的用 tar -zxvf +包的名字 命令解壓。

進入該包的文件夾內,依次執行以下命令:

  ./configure --prefix=/work/installed/apr (注意:configure安裝的文件夾目錄可以自己定義

   make

   make install

安裝 apr-util
 下載地址:http://apr.apache.org/download.cgi
 解壓包: tar -jxvf  apr-util-1.5.3.tar.bz2

進入該文件夾並依次執行:

  ./configure --prefix=/work/installed/apr-util --with-apr=/work/installed/apr

   make

   make install

安裝 pcre
  下載地址:http://pcre.org/
   解壓包:tar -jxvf  pcre-8.35.tar.bz2   

      ./configure --prefix=/work/installed/pcre

       make

       make install

注意如果在安裝 pcre 時,遇到問題:configure: error: You need a C++ compiler for C++ support.
        ubuntu的解決方法sudo apt-get install build-essential

 

       redhat6/centos6 解決方法 :yum安裝包即可:yum install gcc gcc-c++ kernel-devel

 

第二步安裝Apache並配置:

 

安裝:

下載地址:http://httpd.apache.org/
 解壓:tar -jxvf  httpd-2.4.9.tar.bz2

進入解壓后的文件內並執行:

 ./configure --prefix=/work/installed/apache --with-apr=/work/installed/apr --with-apr-util=/work/installed/apr-util --with- pcre=/work/installed/pcre --enable-module=shared

其中--enable-module=shared表示Apache可以動態的加載模塊,為以后安裝php鋪墊。

 

 make

 

 make install

注意:如果安裝錯誤,想重新裝的話,先刪除安裝的文件夾,然后在解壓后的文件夾內執行清除編譯:make clean all

 

第三步配置Apache:

修改配置文件,如果不修改的話就啟動了apache服務的話就會出現問題:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
  解決方法:

在安裝的目錄下修改文件:

命令:vim /work/installed/apache/conf/httpd.conf
         把:
            # ServerName www.example.com:80
         改為:
              ServerName localhost:80

 

然后也可以配置自己的發布主頁目錄:

 

同時也可以添加php的主頁:

 

 

如果 /etc/下有hosts文件的話修改:

 

修改文件: vi /etc/hosts

在后面輸入:192.168.8.119  server.example.com

IP地址改成自己的ip就行了。

啟動apache服務:

輸入命令:/work/installed/apache/bin/apachectl  start

開機自動啟動:vim etc/rc.local
           
添加:/work/installed/apache/bin/apachectl start   這里是apache的安裝目錄里面的配置文件,讓它開機自動啟動就行啦!

 

如果不行的話關閉防火牆:iptables -F

輸入IP地址可以看到:it works!

 

 

但是這種情況必須關閉防火牆,所以需要配置防火牆:

 

打開iptables的配置文件:vi /etc/sysconfig/iptables

添加一條80端口:(如果自己自定義端口的話,填寫自己的端口)

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

 

 

 

 

 

 另外一篇yum安裝Apache以及Apache的配置,僅僅提供參考:

http://www.cnblogs.com/xiaobo-Linux/p/4631675.html


            

 

         

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM