获取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 liuzhen@leimingtech.com

    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错误信息

wKioL1iHTDaxPN69AAAxrpxiGsM068.png-wh_50

需要安装一个微软的V11组件,下载地址:http://www.microsoft.com/zh-CN/download/details.aspx?id=30679

我这里是64位操作系统,所以下载VSU4\vcredist_x64.exe

安装完成后,重新执行“httpd -k install -n Apache24”命令再次加入服务