1. 程式人生 > >免安裝版apache註冊window服務

免安裝版apache註冊window服務

安裝apache:
從官網下載apache2.2.29發現是免安裝版的。首先就需要對apache註冊服務
把apache拷貝到一個目錄下,開啟cmd
執行
httpd.exe -k install -n apache2


D:\tools\Apache22\bin>httpd.exe -k install -n apache2
Installing the apache2 service
The apache2 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
httpd.exe: Syntax error on line 35 of D:/tools/Apache22/conf/httpd.conf: ServerR
oot must be a valid directory


出現error,提示ServerRoot目錄錯誤,修改為conf/httpd.conf檔案中ServerRoot 為"D:\tools\Apache22",apache所在的目錄


再次執行httpd.exe -k install -n apache2發現
D:\tools\Apache22\bin>httpd.exe -k install -n apache2
[Mon Apr 20 16:07:54 2015] [error] apache2: Service is already installed.

該服務已存在
說明已經安裝上了,剛才是測試報錯。
下面開始啟動apache
D:\tools\Apache22\bin>net start apache2
apache2 服務正在啟動 .
apache2 服務無法啟動。

又出現報錯,說明配置檔案還有錯誤。免安裝版真費勁!
檢視log,沒有記錄日誌。只能刪掉window的服務,再次安裝檢視錯誤
刪除服務命令:
D:\tools\Apache22\bin>sc delete apache2
[SC] DeleteService 成功

再次安裝:
D:\tools\Apache22\bin>httpd.exe -k install -n apache2
Installing the apache2 service
The apache2 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
Syntax error on line 179 of D:/tools/Apache22/conf/httpd.conf:
DocumentRoot must be a directory

提示DocumentRoot錯誤
修改為conf/httpd.conf檔案中DocumentRoot為 "D:\tools\Apache22\htdocs"


檢查一下conf檔案中是否還有別的這樣路徑的錯誤,有就修改過來
再次啟動發現還有錯誤,重新安裝服務:
D:\tools\Apache22\bin>httpd.exe -k install -n apache2
Installing the apache2 service
The apache2 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
Syntax error on line 110 of D:/tools/Apache22/conf/extra/httpd-ahssl.conf:
SSLCertificateFile: file 'D:/Apache22/conf/ssl/server.crt' does not exist or is
empty

是ssl驗證錯誤,從目錄結構看,也是路徑的問題,不過我這裡暫時不需要ssl,這個模組用不到,就先註釋掉。重新啟動
D:\tools\Apache22\bin>net start apache2
apache2 服務正在啟動 .
apache2 服務已經啟動成功。

服務啟動成功!
開啟瀏覽器訪問http://127.0.0.1(預設埠80)

出現一個apache的頁面或者It works!則安裝成功!