Home >Backend Development >PHP Problem >What should I do if tomcat does not support php?

What should I do if tomcat does not support php?

藏色散人
藏色散人Original
2020-08-19 10:26:372601browse

Solution to the problem that tomcat does not support php: First, copy the relevant files under "PHP/Java Bridge" to tomcat's lib directory; then modify "web.xml" in the conf folder in the tomcat installation directory file; finally restart tomcat.

What should I do if tomcat does not support php?

Recommended: "PHP Video Tutorial"

Java developers all know that tomcat It is used to deploy java web projects. During this period, there was a project that required the same domain name and port as the PHP project. How to achieve this without using nginx? I learned that tomcat can support running php through Java Bridge. Let’s try it too. YesThe following are the detailed steps.

1. Environment preparation

Installed php environment, installed 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

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

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>

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.

Directly access the file index.php in the webapps directory

025c980fb1ecd83351f4e1e10db86ff1

Appear during access


#                                      

The above is the detailed content of What should I do if tomcat does not support php?. For more information, please follow other related articles on the PHP Chinese website!

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