前言:这几天研究了一下MQTT协议的Android推送由于在网上找到的向推送服务发送信息的服务器是PHP写的,比较懒不愿意重新用apache重新配置PHP环境。所以就找了下题目这种运行PHP的方式。

原文链接:http://www.blogjava.net/freeman1984/archive/2011/06/16/352427.html

环境:
操作系统:IBM aix5.3(当然linux环境和windows下肯定是没问题的)

1 运行php当然首选apache这里就不讲apache方式了,可见于http://www.blogjava.net/freeman1984/archive/2011/06/10/352043.html,但是在aix下php和apache的结合始终没有装好,linux下我试过一点问题没有。有成功的案例可以给个链接看看,谢谢!

下面介绍两种单独使用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.renametojarto$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支持,打开注释即可)
具体如下:


cgi
org.apache.catalina.servlets.CGIServlet

debug
0


cgiPathPrefix
WEB-INF/cgi


passShellEnvironment
true

5

还有后面的mapping



cgi
/cgi-bin/*

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 isWEB-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 isperl.(添加解析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.

我们需要添加executable即可:windows下我的php引擎位置:D:\PHP\php-cgi.exe(aix下为/usr/local/php4/bin/php),因此在第二步里面添加下面参数:

executable
D:\PHP\php-cgi.exe

tomcat6.X下面没有第一步。
4,测试,添加一个web应用,这里使用ROOT即可,编写一个index.php放到webapps/ROOT/WEB-INF/cgi/下面内容:

启动tomcat,访问http://localhost:8080/cgi-bin/index.php即可。
---------------------------------------------------------------------------------

另外一种方式是使用quercus:
Quercus是Caucho公司采用纯Java开发的一个PHP5引擎。基于开源授权协议GPL发布。Quercus自带很多个PHP模块和扩展如 PDF,PDO,MySQL和JSON。可以利用这个引擎在一些JavaEE应用容器(Resin,GlassFish等)中运行PHP程序,也可以在 PHP脚本中调用一些Java服务如JMS。Quercus会预先把PHP文件编译成.java文件,然后再执行。http://quercus.caucho.com/。
当然可以使用resin作为服务器运行也可以,我们这里使用tomcat,需要jdk1.5以上(我试了1,4貌似不行,估计和我下载的quercus有关系),下面是步骤:
1 我们把php项目当做一个web项目放在webapps下,并在里面建WEB-INF\lib目录
2从http://quercus.caucho.com/。下载quercus-4.0.18.zip ,提取里面的web.xml放到
WEB-INF下面,提取里面的cdi-16.jar,resin.jar放到WEB-INF\lib下面。
3 启动tomcat,
4 像访问j2ee web应用一样访问php应用即可。我们现在aix生产环境用的就是这种,比较稳定。

其他方式兄弟们可以扩充。

更多相关文章

  1. Thinkphp MVC以及4种url放文方式
  2. [php入门] 1、从安装开发环境环境到(庄B)做个炫酷的登陆应用
  3. PHP 开发环境配置
  4. PHP环境搭建和编写API接口
  5. PHP是否以不同方式(内部)处理数字索引数组?
  6. centos上安装php运行环境
  7. PHP+Apache环境安装与配置
  8. 定制安全的PHP环境
  9. PHP XAMPP配置PHP环境和Apache80端口被占用解决方案

随机推荐

  1. 1.2 Android 开发环境搭建
  2. Android模仿Buttonbar(style="@android:st
  3. Selector的一些state使用
  4. Android Binder机制学习总结(二)-Driver
  5. Android C 语言读取系统属性
  6. Android ImageView实现上一页,下一页图片
  7. 在ListFragment中使用base-adapter
  8. 使用bitmap缩略图,解决图片大小超过预算的
  9. Android Activity四种加载方式
  10. android 学习之安装