`

tomcat运行php

    博客分类:
  • java
阅读更多
tomcat安装目录下conf/web.xml把下边这段代码注释去掉
<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>
        <init-param>
        		<param-name>executable</param-name>
          	<param-value>E:\Program Files\PHP\php-cgi.exe</param-value> <!--php目录-->

        </init-param>
         <load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
        <servlet-name>cgi</servlet-name>
        <url-pattern>/cgi-bin/*</url-pattern>
  </servlet-mapping>

 

服务器启动
会提示安全java.lang.安全Exception 
说不能加载  org.apache.catalina.servlets.CGIServlet
到conf 下Context.xml改为下边
<Context privileged="true">

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->


</Context>
 
新建一个根据上边web.xml配置的在你的工程/web-inf/ 新建一个cgi目录,写个
helloworld.php
<?php
   echo("helloworld");
?>
运行浏览
   http://localhost:8080/工程名/cgi-bin/hello.php
的时候
php-cgi自己的安全异常又报错
<p>This PHP CGI binary was compiled with force-cgi-redirect enabled.  This
means that a page will only be served up if the REDIRECT_STATUS CGI variable is
set, e.g. via an Apache Action directive.</p>
<p>For more information as to <i>why</i> this behaviour exists, see the <a href="http://php.net/security.cgi-bin



">manual page for CGI security</a>.</p>
<p>For more information about changing this behaviour or re-enabling this webserver,
consult the installation file that came with this distribution, or visit 
<a href="http://php.net/install.windows



">the manual page</a>.</p>
那个version.php里这样写的: <p>This PHP CGI binary was compiled with force-cgi-redirect enabled.  This
means that a page will only be served up if the REDIRECT_STATUS CGI variable is
set, e.g. via an Apache Action directive.</p>
<p>For more information as to <i>why</i> this behaviour exists, see the <a href="http://php.net/security.cgi-bin



">manual page for CGI security</a>.</p>
<p>For more information about changing this behaviour or re-enabling this webserver,
consult the installation file that came with this distribution, or visit 
<a href="http://php.net/install.windows



">the manual page</a>.</p>


解决办法 php.ini中
cgi.force_redirect = 1 改为 cgi.force_redirect=0 

然后重启服务器运行就可以了。我测试了phpcms在tomcat运行情况,还行,有点慢

short_open_tag = On 还改了这,忘了因为什么改成On了

short_open_tag规定了是否可以使用PHP代码开始标志的缩写形式
就是<?  
?>这种方式

我的目的是为了整合discuz 
这是个discuz java 接口
http://code.google.com/p/discuz-ucenter-api-for-java/

php cms乱码问题
http://bbs.phpcms.cn/viewthread.php?tid=110921
修改include/common.inc.php 文件,找到如下代码:

if(GZIP && extension_loaded('zlib')) ini_set('zlib.output_compression', 'On');


把 'On' 改成 'Off'

 

1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics