一、环境
windows server 2003R2 tomcat8 PHP5 MySQL5
很多文档要求将server/lib下servlets-cgi改名为servlets-cgi.jar。从6版本以后,好像就没有server目录,内部已经自动支持cgi,只需要进行配置即可。
Tomcat需要JDK 1.6以上,所以JDK需要先安装好。
二、配置步骤:
1、到C:\php-5.3.10-Win32-VC9-x86目录下将php.ini-development复制一份同一目录下,命名为php.ini
<1>设置extension_dir参数:
extension_dir="C:\php-5.3.10-Win32-VC9-x86\ext"
<1>设置cgi.force_redirect参数:
cgi.force_redirect = 0
2、修改tomcat配置文件
<1>修改conf/web.xml,找到并将cgi的servlet和servlet-mapping的注释去掉
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/..</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<2>修改conf/context.xml
<Context privileged="true">
<3>修改默认网站根目录conf/server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="ROOT\WEB-INF\php-bin" debug="0" reloadable="true">
</Context>
三、测试
建立index.php文件
<?php phpinfo();?>
http://10.0.1.11:8080/index.php
不出意外应该能看到PHP的测试页
本文参考
http://blog.csdn.net/ge_zhiqiang/article/details/6602511
http://www.cnblogs.com/top5/archive/2012/11/29/2794036.html