Manually Installing PHP with Tomcat only

Maybe this post is rare for someone, but I will try to explain how to install PHP working with Tomcat.
This tutorial was tested using Windows 7 of 32 bits.

PHP can works with the library named PECL, the last library that help us to reach the goal is the version 5.2.5.
The PECL 5.2.5 library contains .dll and .jar files that allow us to configure some (not all) PHP version with Tomcat.

All instalation will be made in the folder:



The last version of PHP that works with that PECL version was the 5.2.16. Then I will use the PHP 5.2.16 for Win32.

The contents of the .zip file was uncompressed in the folder:


Inside of this folder there are two files containing templates of configuration of php:
php.ini-dist (for developing) and php.ini-recommended (for production), the difference consist into if the errors will be shown, while the version for developing shows the errors and other information, the version for production does not.
As I’m testing I took php.ini-dist and copied:

copy php.ini-dist php.ini

Coying php.ini

Now lets go to declare to system the path of the PHP.

Now, Is needed to access to variables system, with this manner or according to your preference:

Later, the System Properties dialog box is shown.

Now, We select Advanced tab and press the Environment Variables button.

Here we select the PATH variable and press the Edit button.

Finally modify the variable value adding at the end the path of PHP and press the OK button.


The version of Tomcat tested that worked well was the 7.0.41, because 7.0.42 version had problems with starting and stopping in Windows. Then this post will work with Tomcat 7.0.41 for Win32.

The contents of the .zip file was uncompressed in the folder:


Indicating to Tomcat the path of Java, using Environment Variables

In order to do this, we need to create a new variable with name JAVA_HOME, this variable is checked by Tomcat.
Similarly to declare to path of PHP, but we need to access to Environment Variables, pressing the New button.


In the New System Variable dialog box, we write the name of the variable with JAVA_HOME and the variable value with the path of Java, in my case
C:\Program Files\Java\jdk1.7.0_45\

As you can see the new variable was added.

Now we will make some changes optional on some files in the subdirectory named bin inside the folder of Tomcat.

To start Tomcat silently (without console window popup), change in the file named setclasspath.bat, the line set _RUNJAVA

set _RUNJAVA="%JRE_HOME%\bin\javaw"


Now, lets go to mak changes in the file service.bat in the subdirectory named bin.
To change the service name and name to be displayed (this not alters of functionality of Tomcat’s service), we make this:

set SERVICE_NAME=Tomcat7.0.41
set PR_DISPLAYNAME=Tomcat7.0.41


Later let’s go to modify the description of this service:

set PR_DESCRIPTION=Tomcat 7.0.41 Server


To start Tomcat when Windows does, we make the following change:

"%EXECUTABLE%" //IS//%SERVICE_NAME% --Startup auto


We can modify our web server port, which is initially set to 8080, change it to 80, in this case we need to make changes in the file server.xml in the subdirectory named conf inside the folder of Tomcat.
Editing Server_xml1

You can also set the directory where all web applications will be deployed, for this demostration, I made a new folder named Webapps located inside of ServerWeb.


Inside of this folder, I made other folder named http, specifically a context that represents an application.


These changes in the file server.xml will be:

      <Host name="localhost" appBase="C:/ServerWeb/Webapps"
            unpackWARs="true" autoDeploy="true">
      <Context path="" docBase="http"
            reloadable="true" />

Editing Server_xml2b
With this configuration is possible to deploy applications in other folder different to initially established by default configuration.

We can to make the installation:

service.bat install

Installing service_bat
This service can be verified in Windows.
You can to start this service:


Starting service_bat
To stop this service:


Stoping service_bat
And remove:

service.bat remove

Removing service_bat

Integrating Tomcat with PHP

This changes are in order to use PHP with Tomcat.

Download the PHP Extension Community Library version 5.2.5 for Win32.

For this example, I will unpack the contents to (although this is not necessary):


Copy the file php5servlet.dll from the to the folder C:\ServerWeb\Php_5.2.16\

Copy the file php_java.dll from the to the folder C:\ServerWeb\Php_5.2.16\ext\

In order to make use of php_java.dll we need to make changes in the configuration file of PHP, php.ini, adding a new line like is shown below.


So far everything is ready as far as PHP is concerned.

Copy the file php_java.jar from the to the folder C:\ServerWeb\Tomcat_7.0.41\lib\

Now, we need to make changes in the file named phpsrvlt.jar and create a new file named php5srvlt.jar
First, we need to uncompress the file with (in my case):

"C:\Program Files\Java\jdk1.7.0_45\bin\jar.exe" xfv phpsrvlt.jar

Extracting File from phpsrvlt_jar
Second, as can be seen, two folders are decompressed one call net, inside which there is another folder named php. In this folder php there are multifle files, including one called and another called The contents of both files must be:


Editing Reflect_Properties_b
Editing Servlet_Propertiesb
As you can see, without spaces.
Third, let’s go to create the needed file:

"C:\Program Files\Java\jdk1.7.0_45\bin\jar.exe" cvf php5srvlt.jar net/php/

Adding File to php5srvlt_jar
Fourth, include the php5srvlt.jar file to be used by applications in Tomcat, copying this file into subdirectory lib of Tomcat Directory C:\ServerWeb\Tomcat_7.0.41\lib\ in this case will be available for all applications of Tomcat.

Now, We need to modify the file web.xml (Deployment Descriptor) in the subdirectory named conf inside of Tomcat installation folder.

First change: declaring the name of servlet and its classes.


Editing Web_xml1

Second change: including the mapping of the servlets and classes declared before.

    <!-- The mappings for the PHP servlet -->

Editing Web_xml2

Third change: including and establishing the files and its order in which the default servlet looks for the "welcome file".


Editing Web_xml3

Last we will test the integration, creating a file named test.php inside of
C:\ServerWeb\Webapps\http\, the content is:


Creating test_php
Testing test_php


Acerca de joseluisbz

Hasta ahora, espero actualizarlo después, ahora no.
Esta entrada fue publicada en Instalación, Instalación, Install, Java, JSP, Manually Installation, PHP, Server, Servidores Web, Software, Tomcat, Web Server, Windows y etiquetada , , , , , , , , , , , , , , , . Guarda el enlace permanente.