該篇文章主要講解如何在linux服務器上搭建apache服務器,並修改指定的apache路徑到自定義路徑下
一:檢查服務器上是否已安裝apache,停止並卸載系統自帶apache服務
命令為:rpm -qa|grep httpd
rpm -e --nodeps httpd-tools..

二:卸載完成后,上傳httpd服務安裝所需的所有包

安裝包雲盤地址為:http://pan.baidu.com/s/1qYTgomo 密碼:nk7z
我上傳到了/usr/local目錄下,然后解壓縮並安裝
三:安裝上述安裝包,按順序安裝
- 安裝apr,解決apr not found問題
1 [root@zdhcs5 local]# tar zxvf apr-1.5.2.tar.gz 2 [root@zdhcs5 local]# cd apr-1.5.2 3 [root@zdhcs5 apr-1.5.2]# ./configure --prefix=/usr/local/apr 4 [root@zdhcs5 apr-1.5.2]# make 5 [root@zdhcs5 apr-1.5.2]# make install
- 安裝apr-util,解決apr-util not found問題
1 [root@zdhcs5 local]# tar zxvf apr-util-1.5.4.tar.gz 2 [root@zdhcs5 local]# cd apr-util-1.5.4 3 [root@zdhcs5 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config 4 [root@zdhcs5 apr-util-1.5.4]# make 5 [root@zdhcs5 apr-util-1.5.4]# make install
- 安裝pcre,解決pcre not found問題
1 [root@zdhcs5 local]# unzip -d . pcre-8.39.zip 2 [root@zdhcs5 local]# cd pcre-8.39 3 [root@zdhcs5 pcre-8.39]# ./configure --prefix=/usr/local/pcre 4 [root@zdhcs5 pcre-8.39]# make 5 [root@zdhcs5 pcre-8.39]# make install
- 安裝httpd
1 [root@zdhcs5 local]# tar zxvf httpd-2.4.7.tar.gz 2 [root@zdhcs5 local]# cd httpd-2.4.7 3 [root@zdhcs5 httpd-2.4.7]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre (除了指定Apache的安裝目錄外,還要安裝apr、apr-util、pcre,並指定參數) 4 [root@zdhcs5 httpd-2.4.7]# make 5 [root@zdhcs5 httpd-2.4.7]# make install
四:啟動apache服務並驗證安裝成功,瀏覽器輸入網址出現it works說明安裝成功
1 [root@zdhcs5 bin]# cd /usr/local/apache2/bin/ 2 [root@zdhcs5 bin]# ./apachectl start

五: 修改apache默認展示路徑為自定義路徑
我的自定義路徑為自動化結果報告路徑,即打開網址就能看到linux服務器上運行的自動化結果報告
我的自定義自動化結果報告路徑為(在autotest用戶下):/home/autotest/workspace/auto-project/test-output/html
修改apache的配置文件有兩處需修改:
1 [root@zdhcs5 local]# vi /usr/local/apache2/conf/httpd.conf
- 第一處:修改路徑
修改前為:

修改后為:

- 第二處:修改用戶和組,之所以將daemon用戶修改為autotest是為了讓apache有權限訪問我的自定義路徑,因為我的自定義路徑在autotest用戶下
修改前:

修改后:

保存后退出,重啟apache服務:
1 [root@zdhcs5 local]# cd /usr/local/apache2/bin 2 [root@zdhcs5 bin]# ./apachectl stop 3 [root@zdhcs5 bin]# ./apachectl start
啟動成功后,為了防止在瀏覽器中訪問地址報錯無權限,我們還需要修改自定義文件整個路徑的權限為755
自定義路徑是如上配置的:/home/autotest/workspace/auto-project/test-output/html
用autotest用戶執行下面命令:(autotest為你的自定義路徑的用戶),根據實際修改,
1 [autotest@zdhcs5 html]$ chmod -R 775 /home/autotest/workspace/auto-project/test-output/html
然后在去瀏覽器驗證是否成功,刷新剛剛的瀏覽器地址:

至此linux下安裝apache,並修改默認路徑為自定義路徑就完成了。
