Home >Backend Development >PHP Tutorial >Configure php running environment under linux tomcat
Main steps:
1. Open tomcat's cgi
2. Add php-cgi as the executor of cgi
3. Modify the cgi execution path prefix so that php files in all paths under the project can be executed
Detailed steps:
1. Turn on cgi of tomcat.
Refer to tomcat official website method (http://tomcat.apache.org/tomcat-7.0-doc/cgi-howto.html)
(1) Open conf/web.xml and find the servlet and servlet-mapping named cgi , remove their comments. (Tomcat’s configuration file has a cgi configuration instance by default, but it is commented at the beginning. If it is not found, you can search it online)
(2) Open conf/context.xml and add the privileged="true" attribute to the
The above configuration is for tomcat globally. If it is for a certain application, you need to copy the corresponding configuration to the corresponding WEB-INF.
2. Add php-cgi as the cgi executor
First make sure that php is installed correctly and execute the php-cgi command in the terminal.
Open conf/web.xml, find the servlet named cgi, and add the following configuration to it:
3. Modify the cgi execution path prefix
This part is to allow the php file to be executed directly. The default cgi configuration is: you need to put the php file under WEB-INF/cgi of the project, and then access cgi-bin/xxx.php to execute.
(1) Modify the cgiPathPrefix under the servlet and change WEB-INF/cgi to /, as follows:
(2) Modify cgi under servlet-mapping, change /cgi-bin/* to *.php, as follows:
After completing the above steps, restart tomcat. The php script can be executed under any project, but it cannot be run directly under webapps/, because the tomcat official website explains cgiPathPrefix as follows:
and above.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the configuration of the PHP running environment under Linux tomcat, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.