The content of this article is about how to configure tomcat to run PHP projects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Due to the needs of the company, the author needs to build a PHP project, but the author has not been exposed to any PHP-related development before, so I have basic knowledge about PHP development and environment construction. Neither the requirements nor the compiler understand it. However, the author found during research that even if he integrates the PHP development environment, he still needs the support of the Apache server. Since the tomacat hot deployment project is often used in the recent development of j2ee, it naturally comes to mind that tomcat is also an apache product. Can PHP projects be deployed in tomcat? ? After some research, it was determined to be feasible.
Although you can run the PHP project on tomcat, it does not mean that you do not need to configure the PHP environment, so the first step is to install the PHP environment. Currently, it is common to use apache php mysql to develop a php project, which can be installed separately. But the author is lazy and not interested in studying PHP in depth, so I used xampp, which can install all the environments required for PHP development including the compiler at once.
xampp download address: Download address
Just choose the download version according to our environment:
Install after downloading, as long as Just keep going to the next step. But one of the more important steps is to choose the environment content for installation. Below:
#Two of the uncheckable ones are necessary. That php is the Php development environment we want. The rest are not installed because mysql and tomcat are already installed on my computer. Readers can choose to install it according to their own circumstances.
First we need to download the jar package to support PHP projects.
Download address: Download address
We will put the decompressed jar package into the tomcat lib directory:
Then we need to configure web.xml, which is in the conf directory of tomcat:
We add some content to the
<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>
and then find
<welcome-file>index.php</welcome-file>
At this point, our basic configuration is complete.
I copied our php project into the webapp directory of tomcat.
The above is the detailed content of How to configure tomcat to run PHP projects. For more information, please follow other related articles on the PHP Chinese website!