Home > Article > Backend Development > Detailed Analysis of Integrated Development of PHP and Java Powerful Alliance Page 1/4_PHP Tutorial
As time went by, these two bright spots became brighter and brighter. Soon, they were liked by programmers, so some people had questions: What would happen if the two of them met? Is it possible to combine their strengths?
Try to build a bridge between PHP and Java, use this bridge to establish a communication channel between these two entities, with the help of this bridge, you can develop classes in Java, Their methods are then called in PHP, and similarly, PHP scripts can be used in your Java desktop or web applications.
In this article, you will learn how to:
◆Install and configure the PHP/Java bridge
◆Use Java classes in PHP scripts
◆Use PHP script in Java class
◆Use PHP script in JSP page
Let’s get started!
Install and configure PHP/Java bridge
The latest PHP/Java bridge zip package can be downloaded at http://sourceforge.net/projects/php-java-bridge/, the installation process Depends on which Java platform is chosen to interact with PHP scripts through this bridge.
◆For J2SE, the installation is very simple:
◆Install J2SE 1.6 or higher
◆Install PHP 5.1.4 or higher
◆Unzip the php-java-bridge_5.2.2_j2ee.zip package
Enter the directory you just decompressed from the command prompt, enter:
?>java ?classpath JavaBridge.war TestInstallation
In this folder, you should see an ext directory, which contains four .jar files. Copy the JavaBridge.jar and php-script.jar to the ext folder in your J2SE installation directory. (usually {JAVA_HOME}/jre/lib/ext).
For J2EE, perform the following installation steps:
Copy the JavaBridge.war file to the auto_deploy folder under your J2EE server or servlet engine (Tomcat, Resin, etc.).
Rename the file according to your application, then restart the J2EE server and wait for the automatic deployment process to create the directory associated with the .war file. In this example, the application is called appName.war.
To test the new application from your browser, enter: http://localhost:8080/appName and click test.php.
If your J2EE server is running on a different host and port, the parameters must be modified accordingly.
Note: If you want to run a J2EE/PHP application on Apache or IIS, copy the directory including appName to the document root directory of Apache/IIS.