Resources: http://windows.php.net/download/
1, download the PHP package, this environment for the Windows environment, so download as a ZIP package
2, decompression to Tomcat installation path, renamed to PHP
3, set the environment variable, path add just the path D:\apache-tomcat-8.0.36\php;
CMD input php-v or php-version authentication, if return the following information then PHP setup succeeds
C:\users\administrator>php-v
php 7.2.1 (CLI) (Built:jan 4 2018 04:00:18) (NTS MSVC15 (Visual C + + 2017) x64
)
Copyright (c) 1997-2017 the PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend
4. Configure PHP.ini
Backup php.ini-development to the PHP path and modify the original file to PHP.ini
Modify the following configuration:
(1) Remove extension_dir = "ext" front;
(2) Removing the front of the cgi.force_redirect and modifying the value to 0
5. Configure Tomcat
Open Tomcat's Conf folder, modify the Context.xml file, and add the attribute privileged= "true" in the context, as shown in
Then modify the Web.xml file and add the following <servlet> to the <web-app>, where executable is the php-cgi execution path
<servlet> <servlet-name>php</servlet-name> <servlet-class>org.apache.catalina. Servlets. Cgiservlet</servlet-class> <init-param> <param-name>clientinputtimeout</param-name&
Gt <param-value>200</param-value> </init-param> <init-param> <param-name>de
bug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>executable</param-name> <PARAM-VALUE>D:\APACHE-TOMCAT-8.0.36\PHP\PHP-CG i.exe</param-value> </init-param> <init-param> <param-name>passshellenvironmen t</param-name> <param-value>true</param-value> </init-param> <init-pa Ram> <param-name>cgiPathPrefix</param-name> <param-value>web-inf/phpbin</param -value> </init-param> <load-on-startup>5</load-on-startup> </servlet>
and add the following <servlet-mapping> where Url-pattern is the PHP script path
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>/phpbin/*</ Url-pattern>
</servlet-mapping>
6, testing
Create a new Phpbin folder under Webapps\root\web-inf and place the index.php in the following
<?php phpinfo ();? >
Restart Tomcat, and when the browser enters http://localhost:8080/phpbin/index.php, the configuration succeeds when the interface is opened as follows
The subsequent code is also placed under the Phpbin path and can be opened in the browser.