Thursday 7 April 2016

Running PHP applications in Apache Tomcat 7

Apache Tomcat 7 is a popular server for running Java applications – but say you have a unique instance where you want to run both PHP and Java applications on Tomcat but don’t want to run two separate servers (i.e. Apache HTTPD + Tomcat) to achieve it?

[ Note : This method is not working on tomcat 8. ]

For this we are going to use the PHP – Java Bridge for Tomcat, which is a handy little package that will sort out PHP execution on top of Tomcat.

Step 1: Start download the Javabridge template. This will give you a WAR file that you can directly drop in to your Tomcat server’s webapps folder.
  • For Windows users, the next step is to download PHP and extract it somewhere:
  • For Linux users, just install php5 using apt-get or your preferred package management tool.
Step 2: To add PHP to the PATH variable. Append the path to your PHP folder to the end of your respective PATH variable.

Step 3: Deploy the JavaBridgeTemplate.war file in to your Tomcat server’ or Drop the JavaBridgeTemplate.war file in to your Tomcat server’s webapps folder and start Tomcat.
        How to Deploy .war file into your tomcat server?

  1. Put this url (http://localhost:8080/manager/html) url in web browser then display one prompt where you put your tomcat manager gui username and password and login. 
  2. Then display one tomcat manager dashboard.
  3. There you find "WAR file to deploy" option and select the your JavaBridgeTemplate.war and press deploy button.
Step 4: When you navigate to your server’s Java Bridge folder (this is http://localhost:8080/JavaBridgeTemplate/ by default), you’ll be able to see the Java Bridge’s index page
       If you go tohttp://localhost:8080/JavaBridgeTemplate/test.php, you’ll be able to see the output from the phpinfo() function

If you open up test.php in the JavaBridgeTemplate folder in your Tomcat’s webapp folder, you can edit some of the code:

Now you can deploy any PHP application within the JavaBridgeTemplate folder and rename the folder to whatever you want. You can add many folders like this for different PHP applications.

Note : that the JavaBridge runs PHP as CGI. If you want to enable/disable specific PHP extensions you can simply enable them as you would do normally on your php.ini file.
     

No comments:

Post a Comment

Thanks to comment our blog. i will contact you as soon as possible

Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.Fr...