這篇文章主要介紹了Windows Apache2.4 VC9(ApacheHaus)詳細安裝設定教學,需要的朋友可以參考下
1,Apache下載
選擇一個版本,點擊Download
點擊File For Microsoft Windows
由於Apache HTTP Server官方不提供二進位(可執行)的發行版,所以我們選擇一些貢獻者編譯完成的版本,我們選擇第一個ApacheHaus
點擊ApacheHaus,進入下載頁
#選擇其中一個版本,如果你的Windows還沒安裝對應的VC環境的話,選擇對應的VCRedistribute版本下載安裝。我選擇Apache 2.4VC9版,因為我的電腦中已經安裝了VC9的環境。
點選JumpLinks下第一行的某一個版本,下載對應壓縮包。
2,設定Apache之一--httpd.conf
解壓縮後進入裡面Apache22(最後兩位數字可能不同)資料夾,使用文字編輯器(推薦ultraedit)開啟conf文件夾中的httpd.conf設定檔
找到ServerRoot選項,設定Apache目錄,大約在35行左右,將其改成你的Apache程式的資料夾,範例:
ServerRoot "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22"
找到Listen選項,設定端口,大約46行,一般不修改,使用預設80,在開啟伺服器前請保證80端口未被佔用
找到DocumentRoot選項,修改伺服器根目錄,例:
DocumentRoot "F:/"
請保證此目錄存在,否則伺服器無法正常啟動
修改Directory,保證其與伺服器根目錄相同,只修改下面的第一行中引號部分
<Directory "F:/"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>
找到ScriptAlias選項,設定伺服器腳本目錄,大約326行,一般將其設定為Apache目錄下的cgi-bin資料夾
ScriptAlias /cgi-bin/ "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/cgi-bin"
找到隨後的Directory選項,設定腳本目錄,大約342行,需要設定為和前面的ScriptAlias目錄相同
<Directory "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory>
3,配置Apache之二--ssl配置
如果你這使啟動服務,一般會出現下面的訊息對話框:
提示
Windows不能在本機電腦啟動Apache2.2。有關更多信息,查閱系統日誌文件。如果這是非Microsoft服務,請與廠商聯繫,並參考特定伺服器錯誤代碼1。
確定此問題的原因:
右鍵計算機,點擊管理->Windows日誌->應用程序,顯示如下
<VirtualHost _default_:443> SSLEngine on ServerName localhost:443 SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/server.crt SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/server.key DocumentRoot F:/ # openssl req -new > server.csr # openssl rsa -in privkey.pem -out server.key # openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 2048 <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/Apache22/cgi-bin"> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/logs/ssl_request.log" \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </virtualhost>主要改上文四處地方在130行和152行還有另外兩個VirtualHost,均需修改上述的四個選項範例:130行
<VirtualHost *:443> SSLEngine on ServerName serverone.tld:443 SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/serverone.crt SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/serverone.key DocumentRoot F:/ # openssl req -new > serverone.csr # openssl rsa -in privkey.pem -out serverone.key # openssl x509 -in serverone.csr -out serverone.crt -req -signkey serverone.key -days 2048 <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/Apache22/cgi-bin"> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/logs/ssl_request.log" \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" env=HTTPS </virtualhost>第152行
<VirtualHost *:443> SSLEngine on ServerName servertwo.tld:443 SSLCertificateFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/servertwo.crt SSLCertificateKeyFile C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/conf/ssl/servertwo.key DocumentRoot F:/ # openssl req -new > servertwo.csr # openssl rsa -in privkey.pem -out servertwo.key # openssl x509 -in servertwo.csr -out servertwo.crt -req -signkey servertwo.key -days 2048 <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory "/Apache22/cgi-bin"> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog "C:/Users/myPC/Downloads/httpd-2.2.31-x86-r3/Apache22/ssl_request.log" \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </virtualhost>上述的兩個VirtualHost皆需修改四處這樣,Apache就算配置完了,如果還有問題,可能還需要設定./conf/extra/httpd-ssl.conf,設定方法和設定VirtualHost的相似4,啟動Apache HTTP Server使用Windows命令列
以管理員身分進入Apache程式的資料夾下的bin資料夾,輸入httpd -k install,完成Apache服務的安裝。
然後雙擊bin目錄下的ApacheMonitor.exe,點擊右邊的start啟動伺服器,如果正常,如下圖: 測試一下:5,其它
卸載Apache HTTP Server:
管理員身分進入bin目錄,使用httpd -k uninstall 移除服務
使用httpd -w -n "Apache2" -k start指令啟動伺服器可以顯示啟動過程中的日誌,以便分析錯誤。
以上是Windows Apache2.4 VC9(ApacheHaus)安裝教學課程詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!