Windows上安装Apache httpd和PHP


我下载安装的是Apache(Lounge)2.4的httpd-2.4.27-win32-VC14.zip,PHP7的php-7.0.23-Win32-VC14-x86.zip。
先是httpd -k install,按照报告的信息改了改httpd.conf,主要是两个ROOT路径。
然后装了PHP在G:盘上,又改了改httpd.conf,主要是最后几行。
httpd-2.4.27-win32-VC14\Apache24\conf\httpd.conf:
        ......
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "G:\httpd-2.4.27-win32-VC14\Apache24"
        ......
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "G:\httpd-2.4.27-win32-VC14\Apache24\htdocs"
<Directory "G:\httpd-2.4.27-win32-VC14\Apache24\htdocs">
            ......
</Directory>
            ......
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#

    DirectoryIndex index.html index.php

            ......

#PHP support
LoadModule php7_module "G:/php7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "G:/php7"
                      
 
第35行除了.php外,如果愿意,可以把.htm .txt .html都添上。


不过有一个问题,以上我的机器是已经装过了Visual Studio 2015的。不然可能会报“VCRUNTIME140.dll”缺失。这时要先安装Windows上的 Apache和php7都需要的Visual C++ Redistributable 2015,下载地址:
               https://www.microsoft.com/en-US/download/details.aspx?id=48145
我在另一台未安装Visual Studio的电脑上选了简体中文版的下载装上才行。

此外可能不是Administrator或有防火墙会遇到问题。简要地说,win7启用Administrator的方法: 右击桌面计算机)右键,管理---本地用户和组----用户---找到 administrator 右击 属性,找到“账户已停用” 把勾去掉。 可参见百度知道这个网页。

安装为服务: httpd -k install。

tips: httpd -t 测试配置文件是否OK。

如果不想安装为Windows服务开机自动启动,可以手动直接在cmd下运行:httpd.exe。



Powered by