Home | WebServices | Maven | SOA | REST | Agile & SCRUM | Java & JEE
Homepage

Install PHP with Tomcat 5.5 and above


Java/J2EE applications may exist along with PHP applications . In that case you may wish to enable PHP capability in Tomcat.

This tutorial assumes you have already installed Tomcat and MySQL. If you have not installed Tomcat please do so by visiting Apache Tomcat website. To install MySQL please visit MySQL website

Step 1: Download PHP installer. I prefer the installer version over zip version as the installer populates php.ini file with accurate values.

Step 2: Double click the installer, and continue (by clicking the Next button) till the below Web Server Setup screen. Select "Do not setup a web server" [as Tomcat is not listed].



Step 3: Proceed with Next button till the "Choose Items to Install" screen appears. Expand Extensions[click on the plus] ,scroll down and select MySQL or MySQLi [or both] as shown in the below screen shot.


Step 4: Let us assume you have installed PHP under C drive PHP folder. The directory structure looks as in the below screen shot.


Step 5: As Tomcat does not process PHP code by default, steps 5 to 9 make changes for Tomcat to delegate the processing task to a relevant PHP processor. Please download PECL. Unzip the downloaded PECL zip file to any folder. Look for the file php5servlet.dll and copy it to the root installation directory of PHP [In our example C:\PHP].

Step 6: Add the root PHP directory and the extension directory to environment variable. [In our example C:\PHP and C:\PHP\ext]

Step 7: Go back to the folder where you unzipped PECL. Look for the file phpsrvlt.jar. Unjar [or unzip it using utilities like winzip or winrar or 7-zip] it to any folder. Browse to folder net\php and locate the files servlet.properties and reflect.properties. In both the files change the value assigned to library as php5servlet [The value is the name of the dll copied in step 5] as in the screen shot below.


Step 8: Now jar the content again and make the new phpsrvlt.jar. The only difference in the new jar is that the value for library in the property files are changed [and ofcourse the timestamp of the file]. Copy this jar file into the lib folder of Tomcat. [Note: Copy phpsrvlt.jar into the WEB-INF/lib folder of the desired web application. As in the screen shot my Tomcat root is in C:\tomcat]
libcopy (4K)

Step 9: Now donwload this web.xml and copy it under the WEB-INF folder of the desired web application as in the below screen shot.


Step 10: Restart Tomcat and now we are set to test our newly injected PHP capability. Create a file index.php under the desired web application as in the below screen shot.


Step 11: The content of the PHP should be as in the screen shot below.


Step 12: Now access the PHP page by entering "http://localhost:portno/webappname/index.php" [Note: Please replace portno with a relevant value like 8080 and webappname with your web application name]. In the resulting page, scroll down and look for mysql or mysqli [or both depending on your choice in Step 3]. It should appear in the screen shot below. If it does not appear then proceed with Step 13. If it appears you are one among the luckiest in the world - your Tomcat is ready with PHP capability and MySQL support.


Step 13: Scroll to the top of the PHP info display and look for the value of Configuration File (php.ini) Path. In my case it is C:\WINDOWS as in the screen shot below. Copy 3 files, php.ini [now under C:\PHP], php_mysql.dll [now under C:\PHP\ext] and php_mysqli.dll [now under C:\PHP\ext]. under the above Configuration File (php.ini) Path [that is C:\WINDOWS]. Restart the system. Even after restarting it does not work for you, do not worry. Download the version of php_mysqli.dll from mysql site [this version should be compatible that the one shipped with PHP installer]. Unzip it and you get a php_mysqli.dll. Overwrite the existing file [under C:\WINDOWS as well as C:\PHP\ext with this and restart the system once. Even after this you are not able to find the mysql and mysqli section please mail us. We will help you.


 

 

Copyrights 2008 Thea Solutions
All rights reserved
Powered by 4creativeweb Solutions