Apache2安裝:
文件下載:
httpd-2.4.33.tar.gz http://httpd.apache.org/download.cgi
apr-1.6.3.tar.gz apr-util-1.6.1.tar.gz https://apr.apache.org/download.cgi
pcre-8.39.tar.gz ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
版本根據需要匹配,文章版本不同請忽略...
1)解壓 tar -zxvf httpd-2.4.25.tar.gz
2)安裝
./configure
報錯:configure: error: APR not found. Please read the documentation.
查閱文檔以後發現需要事先安裝很多的依賴
3)APR
tar -zxvf apr-1.5.2.tar.gz
./configure --prefix=/usr/local/apr
--prefix表示將apr安裝到哪個目錄,建議大家都加上該參數設置安裝目錄,以便於後續查找使用
make
make install
安裝apr時運行./configure --prefix=/usr/local/apr時報如下錯:
configure: error: in `/software/apr-1.5.2':
configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
原因及解決辦法:
你的機器裏沒有安裝任何C語言編譯器,可以安裝gcc。 可以在安裝盤裏找到gcc相關的包進行安裝,不過會比較繁瑣,因爲關聯的包會比較多。 如果可以上網,使用yum安裝是比較好的選擇: yum install gcc
安裝完gcc之後,再重新執行./configure --prefix=/usr/local/apr命令時就不會報錯。
4)再次安裝httpd
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr
報錯:configure: error: APR-util not found. Please read the documentation.
5) APR-util
tar -zxvf apr-util-1.5.4.tar.gz
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
如果報錯
make install
6)再次安裝httpd
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config
又報錯:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
7)pcre
tar -zxvf pcre-8.39.tar.gz
./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
make
make install
安裝pcre執行明令./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config時,報如下錯:
configure: error: You need a C++ compiler for C++ support.
原因及解決辦法:
你的機器裏沒有安裝任何C++語言編譯器,可以通過,命令yum install gcc-c++安裝c++編譯器。
安裝完c++之後,再重新執行./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config命令時就不會報錯。
8)再次安裝httpd
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre=/usr/local/pcre/bin/pcre-config
終於沒有問題了
make
make install
9) 修改配置文件: /usr/local/apache/conf/httpd.conf
Listen 9999
啓動Apache2
./apachectl -k start
報錯如下:
AH00557: httpd: apr_sockaddr_info_get() failed for kgc
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
修改配置/usr/local/apache/conf/httpd.conf,增加如下內容:
ServerName localhost:9999
再次啓動,啓動後通過netstat -ltnp命令查看端口狀態
./apachectl -k start/stop/restart 表示 啓動/停止/重啓
注意:如果外網不能訪問,需要關閉防火牆service iptables stop
或者將對應的端口(9999)開放:
直接編輯/etc/sysconfig/iptables文件
1.編輯/etc/sysconfig/iptables文件:vi /etc/sysconfig/iptables加入內容並保存:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
2.重啓服務:/etc/init.d/iptables restart
3.查看端口是否開放:/sbin/iptables -L -n