Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Contributor

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("")->VERSION; echo "<br>\n";


Is it easy to achieve?

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.

  1. Neo’s OSGI container does not like the WAR file structure
  2. A problem here is that you need PHP installed on Neo. JavaBridge acts as a bridge between Java and PHP. Without PHP, an integral part of this bridge is missing and executing PHP scripts won’t work.

Prepare WAR

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

  • JavaProxy.php

And that the folders

  • WEB-INF/pear
  • WEB-INF/platform
  1. exists.

Install PHP

The JavaBridge code checks for an executable PHP binary during startup. Web.xml contains a section where the path to PHP is given.

     <param-value><path to>/php-cgi</param-value>

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.

Compile PHP

First step is of course to compile your own version of PHP for the architecture Neo is using: Linux amd64 ( 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.

How to upload PHP to Neo?

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: Cannot run /usr/sap/ljs/webapps/phpwar/php/bin/php-cgi - exec failed (EACCES - Permission denied).|
#null#Could not start FCGI server: 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| Could not connect to server|

At least the flow to make it work is clear:

  1. Get PHP to Neo
  2. Make it executable
  3. Deploy JavaBridge

Solution: Jenkins

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

Deploy WAR

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.

Final note

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.

Labels in this area