獲取php和Apache安裝文件
php下載地址:http://windows.php.net/download/
獲取安裝包:httpd-2.4.23-win64-VC11.zip
apache下載地址:https://www.apachelounge.com/download/VC11/
獲取安裝包:php-5.6.27-Win32-VC11-x64.zip
我統一解壓到D盤根目錄,對應目錄是:
D:\Apache24
D:\php-5.6.27-Win32-VC11-x64
打開httpd.conf文件 D:\Apache24\conf\httpd.conf
找到以下幾處
ServerRoot "c:/Apache24"
DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/"
<Directory "c:/Apache24/cgi-bin">
將裏面默認的配置路徑“c:/Apache24”統統改爲你當前apache的目錄路徑“D:/Apache24”,如下:
ServerRoot "D:/Apache24"
DocumentRoot "D:/Apache24/htdocs"
<Directory "D:/Apache24/htdocs">
ScriptAlias /cgi-bin/ "D:/Apache24/cgi-bin/"
<Directory "D:/Apache24/cgi-bin">
添加下面幾行,增加對php5的支持:
# php5 support
LoadModule php5_module D:/php-5.6.27-Win32-VC11-x64/php5apache2_4.dll
AddType application/x-httpd-php .php .html .htm
# configure the path to php.ini
PHPIniDir "D:/php-5.6.27-Win32-VC11-x64"
DirectoryIndex index.php index.html 加入index.php識別入口
將Include conf/extra/httpd-vhosts.conf註釋打開,並打開httpd-vhosts.conf文件,開始配置虛擬主機
下面是我的httpd-vhosts.conf配置示例
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:/Apache24/htdocs"
ServerName localhost
ServerAlias 127.0.0.1
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
DirectoryIndex index.php index.html
</VirtualHost>
注意裏面對應的端口需要在httpd.conf配置文件中添加,Listen 80,多個可以分開寫兩個
Listen 80
Listen 8080
在D:\php-5.6.27-Win32-VC11-x64下面找php.ini-development,複製一份,命名爲php.ini
調整一下幾點
On windows:
extension_dir = "D:/php-5.6.27-Win32-VC11-x64/ext"
short_open_tag = On 讓PHP支持簡短標籤寫法,如在設置爲Off時,在寫程序時用<?=$xxx;?>會報錯,要寫成<?php echo $xxx;?>才行
extension=php_mysql.dll
extension=php_mbstring.dll
extension=php_curl.dll 如果未生效將PHP安裝文件夾下的三個文件php_curl.dll(可能在ext文件夾中),libeay32.dll,ssleay32.dll 複製到 %windir%/system32下
extension=php_gd2.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_xmlrpc.dll
date.timezone = Asia/Shanghai 設置時區
將php加入到環境變量
D:/php-5.6.27-Win32-VC11-x64/ext;D:php-5.6.27-Win32-VC11-x64;
打開windows命令行用管理員身份運行
切換到D:\Apache24\bin目錄
加入服務:httpd -k install -n Apache24
卸載服務:sc delete Apache24
apache加入服務過程中出現丟失MSVCR110.dll錯誤信息
需要安裝一個微軟的V11組件,下載地址:http://www.microsoft.com/zh-CN/download/details.aspx?id=30679
我這裏是64位操作系統,所以下載VSU4\vcredist_x64.exe
安裝完成後,重新執行“httpd -k install -n Apache24”命令再次加入服務