安裝apr
下載解壓apr-1.4.5
./configure --prefix=/usr/local/apr make sudo make install
安裝apr-util
下載解壓apr-util-1.5.2
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr make sudo make install
安裝pcre
下載解壓pcre-7.8.tar.gz
./configure --prefix=/usr/local/pcre make sudo make install
安裝httpd
下載解壓httpd-2.4.12
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite make sudo make install
--enable-so 支持DSO模式(動態模塊加載方式)
--enable-rewrite 支持rewrite(地址重定向)
建立軟鏈接
sudo ln -s /usr/local/httpd/bin/apachectl /usr/local/bin/apachectl
啟動
sudo apachectl start
啟動異常
$sudo ./apachectl start
AH00557: httpd: apr_sockaddr_info_get() failed for test10.125.8.116 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
原因:這個問題應該是沒有在 /etc/httpd/conf/httpd.conf 中設定 ServerName。所以apache會用主機上的名稱來取代,首先會去找 /etc/hosts 中有沒有主機的定義。
解決:在/etc/httpd/conf/httpd.conf中添加上ServerName=****
驗證
打開瀏覽器輸入ip,顯示It works! 表示成功了。
添加網頁
文件:/usr/local/httpd/htdocs/test.html
內容
<html> <body> <h1> Test works OK! </h1> </body> </html>
重啟服務
sudo apachectl restart
驗證
配置
1. 修改Web站點目錄
默認的Web站點目錄:/usr/local/apache2/htdocs,如果修改,例如"/home/gyw/WebSite"的目錄作為apache的站點目錄
找到DocumentRoot這一行修改為:DocumentRoot "/home/gyw/WebSite"
找到 <Directory> 這一行修改為:<Directory "/home/gyw/WebSite">