1、搭建PHP+apache環境:
apache: http://www.apachelounge.com/download/ php: http://windows.php.net/download/#php-5.5
版本選擇都下載下傳最新版的64bit
選擇解壓到C槽根目錄上,現在開始配置,PHP是不用動的,隻需要在通路域名時候Apache去找PHP解析就行了,是以僅僅配置:
Apache24\conf\httpd.conf
配置步驟:
1.打開Apache24\conf\httpd.conf
ServerRoot根據自己需求改為apache根目錄。
DocumentRoot 也可以根據自己的喜好修改網站根目錄的地方。别忘了下面的Directory節點裡面的也得改。
2.在一堆LoadModule下面添加
# php7 support
LoadModule php7_module C:/php/php7apache2_4.dll
AddType application/x-httpd-php .php .html .htm
# configure the path to php.ini
PHPIniDir "C:/php"
3.為了讓apache把index.php也設為預設頁把
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
修改為
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
4.管理者權限打開cmd
C:\Apache24\bin\httpd.exe -k install
5.在htdocs中建立一個index.php檔案,然後在浏覽器中輸入127.0.0.1就可以打開了
現在的目标就是
http://localhost/index.php的通路變成
https://localhost/index.php總的來說呢,https和http的差別就是一個多了個s嘛!和這個s代表的是加密,應該說apache自帶一個SSL加密子產品,這個小程式有exe的以及conf,現在就是圍繞這兩個進行操作:
1.修改兩個配置檔案,一個為conf/httpd.conf,另一個為conf/extra/httpd-ssl.conf
在httpd.conf中
a. 删掉以下語句前的’#’
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-ssl.conf
b. httpd-ssl.conf中把相應選項改成如下,有’#’的删掉
SSLCertificateFile "c:/Apache24/conf/server.crt"
SSLCertificateKeyFile "c:/Apache24/conf/server.key"
SSLCACertificateFile "c:/Apache24/conf/ca.crt"
SSLVerifyClient require
SSLVerifyDepth 1
2.生成各種證書
進入Apache24\bin目錄,在對應檔案夾下打開cmd
這裡需要一個openssl的配置檔案openssl.cnf,如果他不在 conf檔案夾下,可以去網上下一個,建議把它放到bin目錄下,這樣子敲指令比較友善
a. 首先要生成伺服器端的私鑰(key檔案):
set OPENSSL_CONF=openssl.cnf
openssl genrsa -des3 -out server.key 1024
b. 生成server.csr ,Certificate Signing Request(CSR),生成的csr檔案交給CA簽名後形成服務端自己的證書.螢幕上将有提示,依照其訓示一步一步輸入要求的個人資訊即可.
openssl req -new -key server.key -out server.csr -config openssl.cnf
c. 對用戶端也作同樣的指令生成key及csr檔案
openssl genrsa -des3 -out client.key 1024
openssl req -new -key client.key -out client.csr -config openssl.cnf
d. CSR檔案必須有CA的簽名才可形成證書.可将此檔案發送到verisign等地方由它驗證,要交一大筆錢,何不自己做CA呢.
openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf
e. 在bin目錄下建立一個demoCA檔案夾,進入它
建立newcerts檔案夾,不需要進入
建立index.txt
建立serial,打開後輸入01儲存即可
f. 用生成的CA的證書為剛才生成的server.csr,client.csr檔案簽名:
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
g. 生成一個ca.pfx,打開IE浏覽器-》工具-》Internet選項-》内容-》證書,按照提示導入,這裡要輸入剛才生成 .pfx 過程中輸入的密碼
openssl pkcs12 -export -in ca.crt -inkey ca.key -out ca.pfx.
h.在httpd.conf中找到下面這句話 #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so 取消注釋(删掉前面的"#")
i.openssl rsa -in server.key -out server.key
把生成的server.key複制到conf目錄下覆寫 然後打開httpd-ssl.conf 找到SSLPassPhraseDialog builtin 在前面加上#
重新開機apache即可https通路項目。
備注:
1、cmd指令界面圖示例:
2、剛剛下載下傳的PHP有兩個ini檔案,他們的差別是
3、上面有個在IE導入證書的我也不知道是什麼來的,效果圖:
通路的效果圖:
在上面的F步驟之中可能出現的錯誤是:
解決辦法:進入demoCA,然後打開index.txt.attr,把它修改成unique_subject = no就可以了
摘自:
http://blog.csdn.net/wlmnzf/article/details/50244409 http://blog.csdn.net/wlmnzf/article/details/50229407 http://www.cnblogs.com/GaZeon/p/6214915.html#ys
現在想知道 httpd.conf 和 \extra\httpd-vhosts.conf 和 \extra\httpd-ssl.conf的關系嗎?就是配置檔案啊,兩個個是配置HTTP的,還有一個是配置HTTPS協定的。