環境:Ubuntu 16.04 LTS , root身份
apache手冊:http://httpd.apache.org/docs/current/install.html
在安裝apache之前,需要先安裝APR、APR-util、PCRE
另外Ubuntu需要安裝libexpat1-dev,CentOS和RHEL需要安裝expat-devel
軟件下載地址:
apr:http://mirrors.hust.edu.cn/apache/apr/
apr-util:http://mirrors.hust.edu.cn/apache/apr/
PCRE:https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
apache:http://mirrors.hust.edu.cn/apache//httpd
安裝PCRE
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz tar -zxf pcre-8.42.tar.gz mv pcre-8.42 pcre cd pcre ./configure --prefix=/usr/local/pcre make make install
安裝Apache
因為是Ubuntu環境,那么需要安裝libexpat1-dev,可以直接執行apt-get install libexpat1-dev即可。
apt-get install libexpat1-dev
下載apr、apr-util、httpd的二進制包。
然后解壓三個壓縮包,將apr和apr-util拷貝到http的srclib目錄中。
#下載文件apr、apt-util、httpd源碼 #解壓 tar zxf httpd-2.4.34.tar.gz tar -zxf apr-1.6.3.tar.gz tar -zxf apr-util-1.6.1.tar.gz #將apr和apr-util拷貝到httpd的srclib目錄下 cp -r apr-1.6.3 httpd-2.4.34/srclib/apr cp -r apr-util-1.6.1 httpd-2.4.34/srclib/apr-util #進入apache源碼目錄 cd httpd-2.4.34 #編譯並安裝 ./configure --prefix=/usr/local/apache2 --with-pcre=/usr/local/pcre make -j 3 && make install
最好執行pcre的路徑,否則在make的時候,系統可能找不到pcre庫
測試
嘗試啟動apache
-> # /usr/local/apache2/bin/apachectl start 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
上面的報錯是因為配置文件(/usr/local/apache2/conf/httpd.conf)中,ServerName設置有問題,
修改ServerName項為localhost,然后在嘗試重啟apache
-> # #修改apache配置文件ServerName項 -> # vi /usr/local/apache2/conf/httpd.conf -> # -> # #重啟apache -> # /usr/local/apache2/bin/apachectl restart
瀏覽器訪問:localhost