Home > Article > Backend Development > Can PHP projects be deployed under Tomcat?
#Can PHP projects be deployed under Tomcat?
PHP projects can be deployed under Tomcat. Tomcat server is a free open source web application server. It is a lightweight application server. In small and medium-sized systems and there are not many concurrent access users It is widely used in various situations and is the first choice for developing and debugging programs.
Tomcat
Tomcat is a core project in the Jakarta project of the Apache Software Foundation, developed by Apache , Sun and other companies and individuals. Due to Sun's participation and support, the latest Servlet and JSP specifications can always be reflected in Tomcat. Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because Tomcat has advanced technology, stable performance, and is free, it is deeply loved by Java enthusiasts and recognized by some software developers, making it a popular Web application server.
Tomcat server is a free open source Web application server. It is a lightweight application server. It is commonly used in small and medium-sized systems and situations where there are not many concurrent access users. It is used to develop and debug JSP programs. first choice. For a beginner, you can think of it this way: when the Apache server is configured on a machine, it can be used to respond to access requests for HTML (an application under the Standard Universal Markup Language) page. In fact, Tomcat is an extension of the Apache server, but it runs independently when running, so when you run tomcat, it actually runs as a separate process from Apache.
The trick is that when configured correctly, Apache serves the HTML pages and Tomcat actually runs the JSP pages and Servlets. In addition, Tomcat, like Web servers such as IIS, has the function of processing HTML pages. In addition, it is also a Servlet and JSP container. An independent Servlet container is the default mode of Tomcat. However, Tomcat's ability to handle static HTML is not as good as the Apache server. Currently, the latest version of Tomcat is 10.0.0-M4.
Deployment tutorial
1. Environment preparation
Deploying the PHP project to tomcat does not mean that you do not need to install PHP. In fact, it still It is necessary to install the php environment. Lao K installed xampp, which is very convenient to install the php environment. For the installation tutorial of xampp, please refer to "How to Install xampp"; in addition to php, you also need to install the java virtual machine and 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 the tomcat lib directory;
Modify the web.xml file in the conf folder in 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>
Then add the following line of code to the welcome-file-list tag
<welcome-file>index.php</welcome-file>
3. Deploy php project
Copy the php project directly to the webapps directory of tomcat, then start tomcat, enter "http://localhost:8080/php project name" in the browser You can see the effect.
Recommended tutorial: "PHP"
The above is the detailed content of Can PHP projects be deployed under Tomcat?. For more information, please follow other related articles on the PHP Chinese website!