tomcat上运行php项目

1、下载安装xampp,下载地址 https://www.apachefriends.org/download.html。
window系统下载window版本,linux下Linux版本,版本7.1到7.3左右
在这里插入图片描述
在这里插入图片描述
2、设置xampp环境变量。
在这里插入图片描述
3、cmd运行php -v,安装成功。
在这里插入图片描述

4、Tomcat环境。解压缩Tomcat压缩包到指定位置
5、修改Tomcat下conf下的web.xml,添加如下内容。

<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>  
      <param-value> D:php\php7.1.26\php-cgi.exe</param-value>  刚才php编译器的安装路径
    </init-param>  
    <init-param>  
        <param-name>passShellEnvironment</param-name>  
    <param-value>true</param-value>  
</init-param>  
    <init-param>  
      <param-name>cgiPathPrefix</param-name>  
      <param-value>WEB-INF/php</param-value>  可修改你自己项目发布的路径
    </init-param>  
     <load-on-startup>5</load-on-startup>  
</servlet>  
<servlet-mapping>  
    <servlet-name>php</servlet-name>  
    <url-pattern>/php/*</url-pattern>  
</servlet-mapping>  

6、修改Tomcat下conf下的context.xml,把标签添加 privileged=“true” ,修改后。
7、在Tomcat下的webapps\ROOT\WEB-INF新建php文件夹,新建index.php,文件内容为

<?php phpinfo();?> 

8、启动tomcat,本机浏览器访问,如果页面出现如下内容

This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.

For more information as to why this behaviour exists, see the manual page for CGI security.

For more information about changing this behaviour or re-enabling this webserver, consult the installation file that came with this distribution, or visit the manual page.

进入xampp安装目录下,进入php目录,修改php.ini (如果没有php.ini,将php_developement.ini复制改为php.ini),将 ;cgi.force_redirect = 1 修改为 cgi.force_redirect = 0
访问页面如下,部署成功

在这里插入图片描述
10,如果遇到启动提示丢失VCRUNTIME140.DLL,这说明你未安装vc++ 2015或者vc++ 2012 安装即可(这应该只针对于windows系统)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值