Home >Backend Development >PHP Problem >Can tomcat run php?
php is a server-side language. To run a php program, it must be on the server. Today I will introduce to you how to build a php service in a web server. The selected web service is tomcat service, so first of all, everyone must install tomcat and be able to use it simply.
1. First download the php program, which is a zip compressed package. As shown below.
2. Unzip the downloaded php compressed package to the installation path of tomcat, and rename it to php, as shown in the figure below.
3. How to check whether php has been installed on your computer:
Click "Environment Variables" in Computer-Properties-Advanced Settings ", add the PATH environment variable, you can add the Admin environment variable, or you can add the system environment variable, depending on your personal needs, add the php decompression path to the PATH. Then open cmd and enter php -v or php -version.
4. Copy php.ini-development under the php path, Rename the copy to php.ini, and then open php.ini with Notepad. (It can be seen that; is the annotation symbol) Modify two of the settings:
Remove the; in front of extension_dir = "ext"
Change cgi.force_redirect to 0, and remove the previous;
That is, cgi.force_redirect = 0
5. Open the conf folder of tomcat.
Select the context.xml file, add the attribute privileged="true" to
#6. Still in tomcat’s conf folder.
Modify the web.xml file and add the following
to
<init-param> <param-name>executable</param-name> <param-value>D:\tomcat\php\php-cgi.exe</param-value> </init-param>
7. Add the following
8. Create a new index.php file with the following content.
Create a new phpbin folder under webapps\ROOT\WEB-INF and place index.php in it.
9. Open tomcat (in the bin folder, double-click startup.bat, on Apple systems, double-click the startup.sh file to open the tomcat service).
Open the browser, enter localhost:8080/phpbin/index.php, and see the following page, indicating that the php configuration is successful!
10. After that, we can happily write PHP code. The written code is placed in the phpbin path and the corresponding code is opened in the browser. script to see the effect.
Recommended video tutorial: PHP video tutorial
The above is the detailed content of Can tomcat run php?. For more information, please follow other related articles on the PHP Chinese website!