在Windows上建立Apache+PHP的环境
阿帕奇
下载 Apache
从Apache Lounge网站下载。
https://www.apachelounge.com/download/#google_vignette
2022/8/19时点上是指” httpd-2.4.54-win64-VS16.zip “的版本。

解压后的文件夹结构如下所示。

将名为「Apache24」的文件夹复制到「c:\var\」目录下。
(如果不存在 var 文件夹,则创建。不一定要以 var 为名称,可以是其他名字。)

Apache的配置
Please note that the paraphrase provided above is written in simplified Chinese script. If you are looking for a paraphrase in traditional Chinese script, please let me know.
编辑httpd.conf文件
C:\var\Apache24\conf\httpd.conf
服务器名称
ServerName localhost:80
服务器根目录
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
↓
Define SRVROOT "c:/var/Apache24"
ServerRoot "${SRVROOT}"
网站根目录
使用SRVROOT来指定放置HTML和PHP文件的文档根路径,因此无需更改。
DocumentRoot "${SRVROOT}/htdocs"
ScriptAlias可以被解释为脚本别名。
由于使用SRVROOT,没有需要更改的CGI别名路径设置。
ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"
cgi-bin目录
由于使用了SRVROOT,因此没有任何变更。
<Directory "${SRVROOT}/htdocs">
听
指定连接口号。
Listen 80
启动Apache
C:\var\Apache24\bin\httpd.exe
执行后会显示以下画面。

在浏览器中打开”http://localhost/”。

只要显示「它起作用!」就表示成功。
PHP是一种通用的脚本语言,特别适用于Web开发。
PHP的下载
从PHP官网上下载。
https://windows.php.net/download
将已经下载的压缩文件解压并移动到「c:\var\」目录下。
在命令提示符中确认操作是否正常。
> php -v
> php -i
只要显示版本和PHP信息,就代表成功。
获取适用于Apache2.4的DLL文件。
如果解压后的PHP文件夹中没有名为”php~apache2_4.dll”的文件,在Apache Lounge网站的”Addtional”页面上下载Apache。

Apache+PHP 可提供网页服务器和服务器端脚本语言,常用于搭建网站和开发动态网页。
将Apache的httpd.conf文件进行修改,以适用于PHP。
加载模块
LoadModule php5_module "C:\var\php-5.6.0-Win32-VC11-x64\php5apache2_4.dll"
目錄
<Directory />
AllowOverride none
Require all denied
</Directory>
↓
<Directory />
AllowOverride All
Require all granted
</Directory>
选择指数
Options Indexes FollowSymLinks
↓
Options Indexes FollowSymLinks ExecCGI
Options +Includes
类型配置
<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types
↓
<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig conf/mime.types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-cgi .cgi
AddType application/x-httpd-cgi .pl
添加处理程序
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi
# For type maps (negotiated resources):
#AddHandler type-map var
↓
目录索引
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
↓
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
PHPIniDir可以被简化为PHP的初始化目录。
PHPIniDir "C:\var\php-5.6.0-Win32-VC11-x64"
确认操作
准备一个用于测试的PHP文件
<?php
phpinfo()
?>
请在浏览器中查看”http://localhost/test.php”的网址。

当您看到显示了phpinfo的页面时,表示成功!
结束。