How to make tomcat support PHP running

慕斯
Release: 2023-04-10 09:26:02
forward
3373 people have browsed it

Java developers all know that tomcat is used to deploy java web projects. It is required to use the same domain name and port as the PHP project. How to achieve this without using nginx? I learned that through Java Bridge, tomcat can support running php. The following are the detailed steps.

1. Environment preparation

Installed the php environment , install java virtual machine, tomcat

The minimum configuration of these tools is php 5.x, java 6 or above, tomcat 6 or above.

2. Configure tomcat

Place JavaBridge.jar of PHP/Java Bridge, Copy php-servlet.jar and php-script.jar to the lib directory of tomcat;

Modify the web.xml file in the conf folder under the tomcat installation directory, and add the following code to the web-app tag ;

<listener>
 <listener-class>php.java.servlet.ContextLoaderListener</listener-class>
 </listener>
 <servlet>
 <servlet-name>PhpJavaServlet</servlet-name>
 <servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
 </servlet>
 <servlet>
 <servlet-name>PhpCGIServlet</servlet-name>
 <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
 <init-param>
 <param-name>prefer_system_php_exec</param-name>
 <param-value>On</param-value>
 </init-param>
 <init-param>
 <param-name>php_include_java</param-name>
 <param-value>Off</param-value>
 </init-param>
 </servlet>
 <servlet-mapping>
 <servlet-name>PhpJavaServlet</servlet-name>
 <url-pattern>*.phpjavabridge</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
 <servlet-name>PhpCGIServlet</servlet-name>
 <url-pattern>*.php</url-pattern>
 </servlet-mapping>
Copy after login

After completing the above steps, restart tomcat, you can execute the php script under any project, but it cannot be run directly under webapps/, because the tomcat official website explains cgiPathPrefix as follows:

The CGI search path will start at the web application root directory File.separator this prefix.

Access files directly in the webapps directory index.php

<?php phpinfo();?>
Copy after login

appears when accessing


## related Learning video sharing:

php video tutorial


               

The above is the detailed content of How to make tomcat support PHP running. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template