1. 程式人生 > >搭建Apache HTTP Server(編譯安裝)

搭建Apache HTTP Server(編譯安裝)

bin con cnn 源碼 err 可能 方法 創建 部分

mkdir /apache #創建一個Apache目錄,位置隨你們習慣
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.bz2 #下載apache源碼
tar -jxvf httpd-2.4.25.tar.bz2 #解壓縮


編譯時可能會有各種問題,比如
checking for APR... no
configure: error: APR not found . Please read the documentation

下載所需軟件包:
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip


解決過程中出現的問題:
1.apr not found問題
tar -zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make && make install

2.APR-util not found問題
tar -zxvf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

3.pcre問題
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=/usr/local/pcre
make && make install


解決上述問題時可能出現gcc/g++:command not found,解決方法:
yum -y install gcc
rpm -qa | grep "g++" #檢查是否缺失相應的包
yum whatprovides "*/g++" #確認未安裝之後,查詢可安裝的包
yum install gcc-c++-XXXXXXXXX.x86_64 #利用yum安裝查詢到的包


安裝apache:
cd httpd-2.4.25 #切換到httpd目錄
./configure --prefix=/opt/httpd-2.4.25 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--enable-so \ #支持DSO模式(動態共享目標)
--enable-mods-shared=most \ #動態編譯大部分常用的模塊
--enable-proxy-balancer=shared \ #支持負載均衡
--enable-proxy-http=shared \ #http代理模塊
--enable-proxy-ajp \ #proxy-ajp模塊
--enable-rewrite #支持地址重寫功能

make
make install

/opt/http-2.4.25//bin/apachectl start
#如果出現httpd: Could not reliably determine the server‘s fully qualified domain name
vi /opt/httpd-2.4.25/conf/httpd.conf
  :?#ServerName
  #新起一行添加ServerName localhost:80
  :wq
/opt/httpd-2.4.25/bin/apachectl stop

cp /opt/httpd-2.4.25/bin/apachectl /etc/init.d/httpd #將apache的啟動腳本復制到/etc/rc.d/init.d這個目錄下
vi /etc/rc.d/init.d/apache

   // 這裏是編輯apache啟動腳本,在開頭的#!/bin/sh 下面加上 #chkconfig: 2345 85 15
chkconfig --add apache //添加apache服務
chkconfig --list apache //列出apache服務
/etc/init.d/httpd start #啟動apache
netstat -lntp| grep 80 (netstat -an | grep:80) #檢驗apache已開啟
lsof -i :80 #查看當前系統文件打開情況

wget http://192.168.10.254 #檢驗是否能訪問
瀏覽器打開 192.168.10.254(It works!)

#瀏覽器訪問不了可能是服務器防火墻開著
service apache status
service apache stop



搭建Apache HTTP Server(編譯安裝)