下面介绍两种单独使用tomcat运行php的:
-------------------------------------------------------------------------------------------
1 使用tomcat内置的cgi支持(需要安装php环境,去官网下载就行了http://www.php.net/downloads.php,要注意的是,我在aix上5.X装不上,用4.X的没问题)
相关文档可见于tomcat的安装目录webapps下面的doc查看cgi-howto.html界面里面有介绍,当然tomcat5.X和6.X有不同的地方:
5.X步骤:
1 :Rename $CATALINA_BASE/server/lib/servlets-cgi.renametojar to $CATALINA_BASE/server/lib/servlets-cgi.jar.
这个大家应该知道意思。
2.Remove the XML comments from around the CGI servlet and servlet-mapping configuration in $CATALINA_BASE/conf/web.xml.(也就是添加cgi的servlet支持,打开注释即可)
具体如下:
<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>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
还有后面的mapping
<!-- The mapping for the CGI Gateway servlet -->
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
3 添加several servlet init parameters which can be used to configure the behaviour of the CGI servlet(添加几个servlet的参数)
cgiPathPrefix - The CGI search path will start at the web application root directory + File.separator + this prefix. The default cgiPathPrefix is WEB-INF/cgi(php文件放置的位置)
debug - Debugging detail level for messages logged by this servlet. Default 0.
executable - The of the executable to be used to run the script. Default is perl.(添加解析php的引擎)
parameterEncoding - Name of the parameter encoding to be used with the GCI servlet. Default isSystem.getProperty("file.encoding","UTF-8").
passShellEnvironment - Should the shell environment variables (if any) be passed to the CGI script? Default isfalse.