1.安装软件 Apache 2.4.16 PHP 5.6.11
Apache下载地址:http://www.apachelounge.com/download/VC11/ (后面再解释为什么不直接从apache.org下载)
PHP下载地址:http://windows.php.net/download#php-5.5
2.Apache 安装
解压Apache,进入Apache bin目录,运行 httpd.exe -k install 将apache以服务的方式安装到windows。监听端口等配置可以修改conf目录下的httpd.conf文件,此处不详述。
3.PHP安装
配置PHP
解压下载好的PHP,将“php.ini-development”更名为“php.ini”。php.ini是记录PHP配置信息的文件。用编辑器打开php.ini,找到如下配置,去掉他们前面的分号以便打开这些配置项(配置文件中的配置项带有分号则表示注释):
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mysql.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
设置扩展目录
extension_dir = "D:/php-5.6.11/ext"
注意此处D:/php-5.6.11/是我自己解压的PHP路径,请自行替换成自己的PHP路径!
4.Apache中设置PHP解析模块
找到http.conf中的#LoadModule最后一行,添加如下配置:
LoadModule php5_module "D:/php-5.6.11/php5apache2_4.dll"
PHPIniDir "D:/php-5.6.11"
AddType application/x-httpd-php .php
5.修改Apache的默认启动路径
定位到 DocumentRoot 配置项,可以配置Apace的文档跟路径,同时记得要修改距离DocumentRoot最近的Directory的路径必须与DocumentRoot一致,如下:
#
# 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.
#
<span style="color:#ff0000;">DocumentRoot "D:/httpd-2.4.16-win64-VC11/Apache24/htdocs"
<Directory "D:/httpd-2.4.16-win64-VC11/Apache24/htdocs"></span>
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
<?php
phpinfo();
?>
,浏览localhost:8080/index.php,此时已经能正常解析php文件了!
在配置过程中碰到的问题:
1.Apache的error.log出现warning信息 PHP Warning: PHP Startup: in Unknown on line 0
排查之后,发现是php.ini中的
extension=php_curl.dll
配置项引发了该问题,去掉该配置,重启Apache,发现warning消失了,但是我们的配置文件中需要用到php_curl.dll的功能,那么按照如下方式可以解决该问题:
将php安装目录添加到系统path中即可。
2.访问localhost:8080/index.php,出现503 Service Unavailable !