tomcat添加支持解析php
2014-05-17 15:41
357 查看
原文地址;http://guojia19890923.blog.163.com/blog/static/112968635201111304137927/
方法一:
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 is
System.getProperty("file.encoding","UTF-8")
.
passShellEnvironment – Should the shell environment variables (if any) be passed to the CGI script? Default
is
false
.
我们需要添加executable 即可:windows下我的php引擎位置:D:\PHP\php-cgi.exe(aix下为/usr/local/php4/bin/php),因此在第二步里面添加下面参数:
<init-param>
<param-name>executable</param-name>
<param-value>D:\PHP\php-cgi.exe</param-value>
</init-param>
tomcat6.X下面没有第一步。
4,测试,添加一个web应用,这里使用ROOT即可,编写一个index.php放到webapps/ROOT/WEB-INF/cgi/下面内容:
<?php
echo(“helloworld”);
?>
启动tomcat,访问http://localhost:8080/cgi-bin/index.php即可。
这种方法比较复杂,下面有更简单的方法
方法二:
就是使用quercus支持
去官网上下载一个http://quercus.caucho.com/,是war格式的,放到tomcat的webapps目录下,运行tomcat,会在当前目录下生成一个名字一样的项目,把php文件放进去就可以了,和管理普通jsp项目一样,简单方便!
方法一:
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 is
System.getProperty("file.encoding","UTF-8")
.
passShellEnvironment – Should the shell environment variables (if any) be passed to the CGI script? Default
is
false
.
我们需要添加executable 即可:windows下我的php引擎位置:D:\PHP\php-cgi.exe(aix下为/usr/local/php4/bin/php),因此在第二步里面添加下面参数:
<init-param>
<param-name>executable</param-name>
<param-value>D:\PHP\php-cgi.exe</param-value>
</init-param>
tomcat6.X下面没有第一步。
4,测试,添加一个web应用,这里使用ROOT即可,编写一个index.php放到webapps/ROOT/WEB-INF/cgi/下面内容:
<?php
echo(“helloworld”);
?>
启动tomcat,访问http://localhost:8080/cgi-bin/index.php即可。
这种方法比较复杂,下面有更简单的方法
方法二:
就是使用quercus支持
去官网上下载一个http://quercus.caucho.com/,是war格式的,放到tomcat的webapps目录下,运行tomcat,会在当前目录下生成一个名字一样的项目,把php文件放进去就可以了,和管理普通jsp项目一样,简单方便!
相关文章推荐
- wdcp添加tomcat,同时支持php和java教程
- php xml 解析成数组(目前仅支持5级,需要照样添加代码就行)
- 在tomcat中添加类型如xls的文件以支持直接在url中打开
- RHEL5 Apache+Tomcat整合,同时支持jsp与php
- IIS7 添加PHP支持(5.2.17及5.3.5)
- tomcat支持php(EXTJS2.0.2)
- Linux下为RPM方式安装的PHP添加GD库支持[原创]
- Tomcat 文件支持格式添加
- PHP添加uuid()模块支持
- PHP中添加memcache扩展支持
- Linux下为RPM方式安装的PHP添加GD库支持
- 为aptana2添加php编辑支持(转)
- 让Tomcat支持PHP
- Vista中给IIS7添加PHP支持-终于算是做成了
- Vista IIS7添加PHP支持的方法
- PHP图片水印函数:支持以图片和文字方式添加水印
- Vista中给IIS7添加PHP支持的设置方法
- Vista,Windows7中给IIS7添加PHP支持
- linux下PHP中添加memcache扩展支持
- MyEclipse9.1中设置默认编码以及添加Tomcat服务器支持