search
Homephp教程php手册如何正确的实现Tomcat支持PHP

如何正确的实现Tomcat支持PHP

Jun 13, 2016 am 11:09 AM
phptomcatexisthowaccomplishussupportarticlecorrectof

我们在这篇文章中为大家详细的讲解了有关Tomcat支持PHP的相关方法,希望对大家有所帮助。在负责一个采用JSP动态网页技术的网站时,刚好手头有写的一部分功能,所以就很直接地想到让Tomcat支持PHP。

Tomcat也是Apache出的,难道就只支持JSP吗?到底能否在Tomcat上用PHP呢?上网搜索了一番,很快有了第一个问题的答案:Tomcat可以支持CGI,如Perl。

但继续搜索,却迟迟无法找到让Tomcat支持PHP的方法,一般都是采取装Apache和Tomcat共存的方法来搭建所谓的支持PHP+JSP的Web平台。

当然,其实PHP本身也支持CGI方式的使用,所以就自己动手试了一试(在Windows操作系统上):先按照附文的做法让Tomcat支持CGI,然后再改web.xml,在servlet-name为cgi的一段配置中加上:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> </span><span class="tag-name">init-param</span><span class="tag">></span><span>   </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">param-name</span><span class="tag">></span><span>executable</span><span class="tag"><span> /param-name</span><span class="tag">></span><span>   </span></span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">param-value</span><span class="tag">></span><span>php</span><span class="tag"><span> /param-value</span><span class="tag">></span><span>   </span></span></span></li>
<li><span class="tag"><span> /init-param</span><span class="tag">></span><span>  </span></span></li>
</ol>

并把PHP安装路径加入Path,这样Tomcat就能运行到PHP.exe了。重启Tomcat后,在WEB-INF目录下新建一个cgi目录,把php文件放在这里,然后访问时用虚拟映射出来的cgi-bin目录来访问这些PHP文件。

但是如果对PHP文件不加任何改动的话,可能会发现什么输出都没有。需要在PHP文件头部加一行,输出两个回车: echo "nn"; 原因不太清楚。可能在等待Content-type输入,或是Perl的cgi程序风格。

但这样配置,PHP(4.1.0以上版本)中$_REQUEST、$_GET、$_POST等变量就无法用了,只能从服务器变量或环境变量中获取QueryString了:$_SERVER["QUERY_STRING"]、$_ENV["QUERY_STRING"]。也许不支持表单的POST提交了……具体还没试过。

由于对Tomcat不熟悉,所以这些只是在现在方法上的小修小补,可能有好的Tomcat支持PHP的做法,还希望大家不吝指教!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment