php+tomcat 配置运行环境

时间:2024-03-11 18:32:42

为了学习php,本教程始于:2017.11.16

 

完成时的截图!

 

 

1.首先下载: VC 2015++

  点击下载

 

2.

把下载好的php复制到本目录,然后解压并且重命名为“php”,如果没有下载php,请 点击下载

 

 

extension_dir = "ext"
cgi.force_redirect = 0

 

3.修改content.xml

 

或者直接把下面的代码拷贝进去即可  Tomcat里面conf的content.xml 

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

 

4.修改web.xml,在tomcat里面的conf文件夹下面的web.xml修改一下

 

拷贝以下代码到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>

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

测试文件是:

index.php

代码如下(copy复制即可)

<?php phpinfo()?>

 

测试地址是:

本地地址