
2.3 在Windows下安装配置PHP+Apache开发环境
关于在Windows下面安装配置PHP+Apache的开发环境,下面将以apache-2.2.4和php-5.2.2为例,详细介绍其安装、配置过程和各种注意事项(以下全部过程都由笔者亲自实验所得)。
2.3.1 安装Apache
首先从Apache官方网站http://httpd.apache.org/download.cgi上下载Apache的安装程序apache_2.2.4-win32-x86-openssl-0.9.8d.msi,鼠标双击进入安装向导界面,如图2-1所示:


图2-1 Windows Apache安装图1
在图2-1中,阅读完Apache的介绍后,点击Next按钮进入Apache服务器域名权限等配置界面,如图2-2所示:


图2-2 Windows Apache安装图2
在图2-2中,配置完Apache服务器的各种选项之后,单击Next按钮进入Apache服务器最后的安装向导界面,如图2-3所示:

图2-3 Windows Apache安装图3

在安装向导程序结束后,可以在Windows的开始程序菜单中找到Apache服务器的各种系统功能菜单,这些菜单可以很简单地对其进行配置、监控、启动、关闭、重启等操作,如图2-4所示。

图2-4 Windows Apache系统菜单图
在图2-4中的菜单中选择Start选项来启动Apache服务器,然后打开IE浏览器,并输入127.0.0.1来访问Apache服务器,如图2-5所示:

图2-5 Windows Apache成功安装测试图
Windows下Apache默认的输出编码为英文,若要让Apache默认的输出为中文就需要修改Apache配置文件httpd-languages.conf,如图2-6所示:

图2-6 Windows Apache成功安装测试图
2.3.2 以模块方式安装PHP
首先从PHP官方网站http://cn.php.net/downloads.php上下载PHP5的安装程序php-5.2.2-win32-installer.msi,鼠标双击进入安装向导界面,如图2-7所示:

图2-7 Windows PHP安装图1
在图2-7中,配置完PHP安装路径后单击Next按钮进入PHP安装模式选择向导界面,如图2-8所示。


图2-8 Windows PHP安装图2
在图2-8中,配置完PHP组件后单击Next按钮进行安装,最后出现安装结束向导界面,如图2-9所示:

图2-9 Windows PHP安装成功图
以模块方式安装好PHP后,可以通过查看Apache的配置文件httpd.conf来确认是否已经配置好了模块模式,如图2-10所示:

图2-10 Windows PHP模块配置图
最后,可以通过运行本章后面介绍的第一个PHP程序来检测是否成功配置和启用了PHP的模块模式,如图2-11所示:

图2-11 Windows PHP模块测试图
2.3.3 以CGI方式安装PHP
以CGI方式安装PHP与模块方式安装有一些差别,下面我们就来介绍如何用CGI方式安装PHP。
首先按照模块方式的步骤安装至配置安装方式的界面,并选择Apache CGI方式安装,如图2-12所示,然后按照模块方式接下来的步骤安装即可。

图2-12 Windows PHP CGI安装图
以CGI方式安装好PHP后,可以通过查看Apache的配置文件httpd.conf来确认是否已经配置好了CGI模式,如图2-13所示:

图2-13 Windows PHP CGI配置图
通过运行本章后面介绍的第一个PHP程序来检测是否成功配置和启用了PHP的CGI模式,如图2-14所示。

图2-14 Windows PHP CGI测试图