Christian
Christian

Reputation: 1

Failed to Start ["php-cgi","-v"]

Im trying to build php-java bridge but i always get error with "HTTP Status 500 - php.java.bridge.http.FCGIConnectException: Could not connect to server".

Fatal Error: Failed to start PHP ["php-cgi", "-v"], reason: java.io.IOException: Cannot run program ""php-cgi"" (in directory "C:\Users\Rob"): CreateProcess error=2, The system cannot find the file specified Could not start FCGI server: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]

I already read this one this but didnt get how to resolve it

I'm using xampp - tomcat on localhost:8080/JavaBridge

how to resolve this problem?

Upvotes: 0

Views: 2395

Answers (1)

First of all, the php-cgi binary is not technically required to run the bridge for regular PHP->Java interactions... (for Java->PHP it is).

Unfortunately, if you're using the generic JavaBridgeTemplate.war, the (Java->PHP) mode is enabled by default and will look for a php-cgi executable, which could not be determined automatically on your system.

The solution you've mentionned allows to specify the location of the php-cgiexecutable when using the integrated standalone server. But if you use Tomcat, this won't work (not 100% correct, but let's assume it that way)

So what to do ?

Under Tomcat, the bridge parameters are stored in a /WEB-INF/web.xml file inside the war file. I'll assume you've downloaded and use one from the sourceforge repo.

Simply open the JavaBridgeTemplate<version>.war file with an archive manager (a war is pretty much a zip) and edit the /WEB-INF/web.xml with one of the solutions below:

  1. Either completly remove support for Java->PHP.

This can be achieved by removing the registration of the PhpCGIServlet entry. Check for the following xml lines and place comments around (<!-- and -->).

<servlet>
  <servlet-name>PhpCGIServlet</servlet-name>
  <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
  <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>PhpCGIServlet</servlet-name>
  <url-pattern>*.php</url-pattern>
</servlet-mapping>

(PS: I'm not totally sure this solution works for all versions of the bridge)

  1. Or specify the location of the php-cgi binary.

First ensure you have a php-cgi executable and take note of its location (could be c:/xampp/php/php-cgi.exe in your case, but I'm not using windows). Then look for

<context-param>
    <param-name>prefer_system_php_exec</param-name>
    <param-value>On</param-value>
</context-param>

<!-- Location of your system PHP executable. Default is /usr/bin/php-cgi or c:/Program Files/PHP/php-cgi.exe
     If exported (Linux) or on the path (Windows) you can use 'php-cgi' as a platform
     independent pointer to the executable
-->
<context-param>
    <param-name>php_exec</param-name>
    <param-value>php-cgi</param-value>
    <!-- As an example, the param value
         of the php-cgi executable could be:
            <param-value>/usr/bin/php-cgi5.6</param-value>
            <param-value>/usr/bin/php-cgi7.0</param-value>
            <param-value>c:/Program Files/PHP/php-cgi.exe</param-value>
    -->
</context-param>

Ensure that <param-value>c:/Program Files/PHP/php-cgi.exe</param-value> contains the location of the php-cgi.


Then save your changes (be sure the web.xml is well saved in the .war file) and redeploy on your Tomcat server.

Haven't tested but hope it helps.

PS:

  • If possible upgrade to Tomcat 7 or 8.

  • Note the existence of the soluble-japha reworked client (works with the java bridge server), that'll help a lot ;)

Upvotes: 0

Related Questions