Você está na página 1de 21

joseluisbz's Blog

Este Blog trata de aspectos del rea del Software, Sistemas, Hardware o Electrnica

Saltar al contenido.

Inicio
About
Obtaining Size or Dimension of Images
Manually Installing Php, Tomcat and Httpd Lounge

Manually Installing PHP with Tomcat only


Publicado en 2013/10/26de joseluisbz

2 Votes

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:
C:\ServerWeb\

PHP

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:
C:\ServerWeb\Php_5.2.16\

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 Im testing I took php.ini-dist and copied:
copyphp.inidistphp.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 OKbutton.

Tomcat
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:
C:\ServerWeb\Tomcat_7.0.41\

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
withJAVA_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 bininside the folder of Tomcat.
To start Tomcat silently (without console window popup), change in the file
namedsetclasspath.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 Tomcats service), we make this:
setSERVICE_NAME=Tomcat7.0.41
setPR_DISPLAYNAME=Tomcat7.0.41

Later lets go to modify the description of this service:

setPR_DESCRIPTION=Tomcat7.0.41Server

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


"%EXECUTABLE%"//IS//%SERVICE_NAME%Startupauto

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 confinside the folder of Tomcat.

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.
C:\ServerWeb\Webapps\

Inside of this folder, I made other folder named http, specifically a context that
represents an application.
C:\ServerWeb\Webapps\http\

These changes in the file server.xml will be:


<Hostname="localhost"appBase="C:/ServerWeb/Webapps"
unpackWARs="true"autoDeploy="true">
<Contextpath=""docBase="http"
reloadable="true"/>

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.batinstall

This service can be verified in Windows.

You can to start this service:


startup.bat

To stop this service:


shutdown.bat

And remove:
service.batremove

IntegratingTomcatwithPHP
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):
C:\ServerWeb\Pecl_5.2.5\

Copy the file php5servlet.dll from the pecl-5.2.5-Win32.zip to the


folderC:\ServerWeb\Php_5.2.16\
Copy the file php_java.dll from the pecl-5.2.5-Win32.zip to the
folderC:\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.
extension=php_java.dll

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


Copy the file php_java.jar from the pecl-5.2.5-Win32.zip to the
folderC:\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:\ProgramFiles\Java\jdk1.7.0_45\bin\jar.exe"xfvphpsrvlt.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 calledreflect.properties and another
called servlet.properties. The contents of both files must be:
library=php5servlet

As you can see, without spaces.


Third, lets go to create the needed file:
"C:\ProgramFiles\Java\jdk1.7.0_45\bin\jar.exe"cvfphp5srvlt.jarnet/php/

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.
<servlet>
<servletname>php</servletname>
<servletclass>net.php.servlet</servletclass>
</servlet>
<servlet>
<servletname>phpformatter</servletname>
<servletclass>net.php.formatter</servletclass>
</servlet>

Second change: including the mapping of the servlets and classes declared
before.
<!ThemappingsforthePHPservlet>
<servletmapping>
<servletname>php</servletname>
<urlpattern>*.php</urlpattern>
</servletmapping>
<servletmapping>
<servletname>phpformatter</servletname>
<urlpattern>*.phps</urlpattern>
</servletmapping>

Third change: including and establishing the files and its order in which the
default servlet looks for the "welcome file".
<welcomefile>index.php</welcomefile>

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

<?
phpinfo();
?>

Você também pode gostar