Home Backend Development PHP Problem How to set up tomcat php environment

How to set up tomcat php environment

Dec 21, 2021 am 09:25 AM

How to build tomcat php environment: 1. Copy the downloaded php to the corresponding directory; 2. Unzip and rename it to "php"; 3. Modify content.xml; 4. Modify the conf in tomcat web.xml in the folder.

How to set up tomcat php environment

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to set up tomcat php environment?

php tomcat configures the running environment

Screenshot when completed!

Although you can run php projects 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.

Copy the downloaded php to this directory, then unzip it and rename it to "php". If you have not downloaded php, please xampp download address:

https://www.apachefriends.org/zh_cn/index.html
Copy after login

Just choose the download version according to our environment:




# # Install after downloading, 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 them cannot be removed. It is 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.

##
extension_dir = "ext"cgi.force_redirect = 0
Copy after login

3. Modify content.xml


Or just copy the code below

The content.xml of conf in Tomcat

<Context privileged="true">

    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>
Copy after login
4. Modify web.xml, modify the web.xml under the conf folder in tomcat

拷贝以下代码到web.xml。建立一个servlet (xml格式可以会有变化,建议你去格式化xml以修正博客编写时以及复制造成的误差)

拷贝到第一个默认的servlet下面即可

<servlet>
        <servlet-name>php</servlet-name>
        <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
        <init-param>
            <param-name>clientInputTimeout</param-name>
            <param-value>200</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>executable</param-name>
            <!--php下载解压/安装的路径-->
            <param-value>F:\tomcat\php\php-cgi.exe</param-value>
        </init-param>
        <init-param>
            <param-name>passShellEnvironment</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cgiPathPrefix</param-name>
            <!--自己tomcat下对应的url-->
            <param-value>WEB-INF/phpbin</param-value>
        </init-param>
        <load-on-startup>5</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>php</servlet-name>
        <url-pattern>/phpbin/*</url-pattern>
    </servlet-mapping>
Copy after login

5.新建一个文件夹phpbin ,然后里面放php文件

测试文件是:

index.php

代码如下(copy复制即可)

<?php phpinfo()?>
Copy after login

测试地址是:

本地地址

推荐学习:《PHP视频教程

The above is the detailed content of How to set up tomcat php environment. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8 JIT (Just-In-Time) Compilation: How it improves performance. PHP 8 JIT (Just-In-Time) Compilation: How it improves performance. Mar 25, 2025 am 10:37 AM

PHP 8's JIT compilation enhances performance by compiling frequently executed code into machine code, benefiting applications with heavy computations and reducing execution times.

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. OWASP Top 10 PHP: Describe and mitigate common vulnerabilities. Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP Secure File Uploads: Preventing file-related vulnerabilities. PHP Secure File Uploads: Preventing file-related vulnerabilities. Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Encryption: Symmetric vs. asymmetric encryption. PHP Encryption: Symmetric vs. asymmetric encryption. Mar 25, 2025 pm 03:12 PM

The article discusses symmetric and asymmetric encryption in PHP, comparing their suitability, performance, and security differences. Symmetric encryption is faster and suited for bulk data, while asymmetric is used for secure key exchange.

PHP Authentication & Authorization: Secure implementation. PHP Authentication & Authorization: Secure implementation. Mar 25, 2025 pm 03:06 PM

The article discusses implementing robust authentication and authorization in PHP to prevent unauthorized access, detailing best practices and recommending security-enhancing tools.

How do you retrieve data from a database using PHP? How do you retrieve data from a database using PHP? Mar 20, 2025 pm 04:57 PM

Article discusses retrieving data from databases using PHP, covering steps, security measures, optimization techniques, and common errors with solutions.Character count: 159

PHP CSRF Protection: How to prevent CSRF attacks. PHP CSRF Protection: How to prevent CSRF attacks. Mar 25, 2025 pm 03:05 PM

The article discusses strategies to prevent CSRF attacks in PHP, including using CSRF tokens, Same-Site cookies, and proper session management.

What is the purpose of prepared statements in PHP? What is the purpose of prepared statements in PHP? Mar 20, 2025 pm 04:47 PM

Prepared statements in PHP enhance database security and efficiency by preventing SQL injection and improving query performance through compilation and reuse.Character count: 159

See all articles