Of course 😉
Excerpt of index.php where a Java object is created using PHP:
/* create a Java object from the PHP object */
$javaObject = java_closure(new MyClass());
echo "PHP says that Java says: "; echo $javaObject; echo "<br>\n";
echo "<br>\n";
echo java("php.java.bridge.Util")->VERSION; echo "<br>\n";
Result:
Depends 😉 For running PHP in Java, there is program available: PHP Java Bridge. This PHP to Java project is meant to be executed inside a servlet container like Tomcat. Therefore, running it inside Neo should not be a problem: just deploy JavaBridge.war to Neo. As this is too easy, some pre-requisites and problems have to be solved before PHP will work inside Neo.
First issue is the easiest one to solve. Make sure to put at least an empty file into each folder and make sure that the folder.
/java contains the files
And that the folders
The JavaBridge code checks for an executable PHP binary during startup. Web.xml contains a section where the path to PHP is given.
<context-param>
<param-name>php_exec</param-name>
<param-value><path to>/php-cgi</param-value>
</context-param>
Now, while you can define a random path to the binary, it is still a problem as you do not have a PHP binary available in Neo. While you can include the PHP binaries inside the WAR, they won`t be marked executable (X-flag) when deployed.
Note: not sure if this is a feature of WAR deploy, as it makes sense to not have the files with the execution flag set or if it is how the zip was created: from Linux to Windows to Neo. Result: while the PHP binary is there, it is not executable and therefore the deploy of JavaBridge won`t work.
First step is of course to compile your own version of PHP for the architecture Neo is using: Linux amd64 (http://www.php.net/downloads.php). Take either your Linux machine or a (Debian) Linux VM, download PHP and compile it. On Debian, install gcc and make: “apt-get install build-essentials”. Then run in the PHP directory configure to see if any dependencies are missing and than make, test, install and finally zip the binaries.
Easiest alternative is to include the PHP binaries in the WAR file (under, for example, /php) and reference this location in the web.xml: /usr/sap/ljs/webapps/NAMEOFWAR/php/bin/php-cgi. In case the X-flag is still set, this should work. If not, when starting the application, the log will clearly show that:
#Fatal Error: Failed to start PHP [/usr/sap/ljs/webapps/phpwar/php/bin/php-cgi, -v], reason: java.io.IOException: java.io.IOException: Cannot run /usr/sap/ljs/webapps/phpwar/php/bin/php-cgi - exec failed (EACCES - Permission denied).|
#null#Could not start FCGI server: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [/usr/sap/ljs/webapps/phpwar/php/bin/php-cgi, -v] |
#Timeout waiting for PHP FastCGI daemon|
#null#php.java.bridge.http.FCGIConnectException: Could not connect to server|
At least the flow to make it work is clear:
Jenkins can help. With Jenkins, you cannot only compile source code, execute maven and ant; you can also execute shell commands, including chmod. After checking in all the files into a source code repository and let Jenkins download it, it is possible to execute the three steps in the right order.
Copy PHP: Solved by an ant task.
Make PHP executable: Solved by executing a shell command.
Result of this command:
+ chmod 755 /usr/sap/ljs/php/bin/pear /usr/sap/ljs/php/bin/peardev /usr/sap/ljs/php/bin/php-cgi […]
+ ls -alhR /usr/sap/ljs/php/bin
/usr/sap/ljs/php/bin:
total 40M
drwxr-xr-x 2 ljs ljs 4.0K Nov 22 13:43 .
drwxr-xr-x 6 ljs ljs 4.0K Nov 22 13:43 ..
-rwxr-xr-x 1 ljs ljs 883 Nov 22 13:43 pear
[…]
-rwxr-xr-x 1 ljs ljs 20M Nov 22 13:43 php-cgi
-rwxr-xr-x 1 ljs ljs 2.2K Nov 22 13:43 php-config
Now PHP can be executed.
+ /usr/sap/ljs/php/bin/php-cgi -v
PHP 5.4.8 (cgi-fcgi) (built: Nov 20 2012 16:15:48)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
While now it is possible to deploy the WAR to whatever other JEE server or Neo instance, a simple copy deploys it into the local instance. This is achieved by issuing another ant task:
JavaBridge is deployed and works. To access it only the URL has to be changed to use the name of the WAR file.
Don`t know about you, but I will from now on* continue to use Jenkins for deploying my Neo apps.
*In case someone now also wants to use a CI solution for deployment of Neo apps inside Neo: I claim all IP, TM, Patents and everything else on the idea to run Jenkins for builds on Neo 😄
Actually, I am wondering why SAP is not offering a CI environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |