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>
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();?>
appears when accessing
## related Learning video sharing:
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!