Home > Operation and Maintenance > Linux Operation and Maintenance > How to configure tomcat to run PHP projects

How to configure tomcat to run PHP projects

坏嘻嘻
Release: 2018-09-15 17:20:33
Original
7681 people have browsed it

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.

1. Foreword

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.

2. Install the PHP environment

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:

How to configure tomcat to run PHP projects

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:

How to configure tomcat to run PHP projects

#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.

3. Configure tomcat to support PHP projects

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:

How to configure tomcat to run PHP projects


Then we need to configure web.xml, which is in the conf directory of tomcat:

We add some content to the node:

	<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

and then find node, add the following welcome content:

<welcome-file>index.php</welcome-file>
Copy after login

At this point, our basic configuration is complete.

4. Add the php project to tomcat

I copied our php project into the webapp directory of tomcat.

How to configure tomcat to run PHP projects

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!

Related labels:
source:php.cn
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