Current Location: Home> Latest Articles> How to Deploy PHP Projects on Tomcat Server

How to Deploy PHP Projects on Tomcat Server

gitbox 2025-07-01

Introduction

Tomcat is one of the most popular web application servers, but by default, it does not support PHP. Therefore, deploying PHP projects on Tomcat becomes a necessity for many developers. This article will guide you through the process of successfully deploying PHP on Tomcat.

Preparation

Before configuring Tomcat and PHP, make sure you have the following resources ready:

  • Tomcat installation package (available for download from the official Tomcat website)
  • PHP installation package (available for download from the official PHP website)

Configure Tomcat

Install Tomcat

First, download and install Tomcat by following the installation wizard.

Edit Tomcat Configuration

Next, create a php directory in the Tomcat installation folder and place an index.php file inside it. Then, modify the Tomcat configuration file `server.xml` and add the following content:

<context path="/php" docbase="D:/tomcat/php" debug="0" crosscontext="true"></context>
<resources classname="org.apache.naming.resources.ProxyDirContext" allowLinking="true" />

Here, "D:/tomcat/php" is the path to your PHP directory.

Configure PHP

Install PHP

Download and install PHP by following the installation wizard, and select the appropriate installation directory and web server settings during the installation process.

Edit php.ini File

In the PHP installation directory, locate the php.ini file and make the following modifications:

extension_dir = "\php\ext"
extension=php_openssl.dll

Then, copy this php.ini file into the conf directory of your Tomcat installation.

Test PHP

After completing the steps above, start the Tomcat server and visit http://localhost:8080/php/index.php in your browser to check if the PHP page works correctly.

Conclusion

By following the steps in this article, you have successfully deployed a PHP project on Tomcat. The methods described here are for reference, and you may need to adjust the configuration based on your specific setup. If you encounter any issues, it is recommended to consult the official documentation of Tomcat and PHP, or seek help from relevant developer communities.