title: PHP JavaBridge permission error
body: <p>I have an existing large(ish) PHP web app (using Apache and MySQL) which now needs to be able to call a Java based reporting engine. So, what I'm trying to achieve is the ability to access java classes from within the existing PHP app.</p>
  
  <p>So far, on a new dev server, I have successfully installed the open source PHP-Javabridge project (http://php-java-bridge.sourceforge.net/pjb/index.php) and have it running under Tomcat (7.0.22) on a Fedora 15 box using port 8080. I can't use the Zend Javabridge because of hosting restrictions for the live system and unfortunately changing provider is not an option at the moment.</p>
  
  <p>I also have Apache and PHP running on the dev box using port 80.</p>
  
  <p>I can access the JavaBridge webapp in Tomcat and all the PHP examples work fine. However, I am running into a problem when trying to access the JavaBridge from within my existing application.</p>
  
  <p>I am assuming that it should be possible for me to call the php 'java' function from within a script located in the web root for Apache (/var/www/html).</p>
  
  <p>I have used the script supplied in the JavaBridge application as follows:</p>
  
  <pre><code>&lt;?php
      require("http://127.0.0.1:8080/JavaBridge/java/Java.inc");
      echo java("java.lang.System")-&gt;getProperties();
  ?&gt;
  </code></pre>
  
  <p>This produces the following errors in /etc/httpd/logs/error_log</p>
  
  <blockquote>
    <p>[Tue Nov 22 15:01:08 2011] [error] [client ::1] PHP Warning:  require_once(http://localhost:8080/JavaBridge/java/Java.inc): failed to open stream: Permission denied in /var/www/html/javatest.php on line 2</p>
    
    <p>[Tue Nov 22 15:01:08 2011] [error] [client ::1] PHP Fatal error:  require_once(): Failed opening required 'http://localhost:8080/JavaBridge/java/Java.inc' (include_path='.:/php/includes:/usr/share/apache-tomcat-7.0.22/webapps/JavaBridge') in /var/www/html/javatest.php on line 2</p>
  </blockquote>
  
  <p>The other suggested script is: (note: I have a copy of Java.inc in /var/www/html)</p>
  
  <pre><code>&lt;?php
      define("JAVA_HOSTS", "127.0.0.1:8080");
      define("JAVA_SERVLET", "/JavaBridge/servlet.phpjavabridge");
      require_once("./Java.inc");
      echo java("java.lang.System")-&gt;getProperties();
  ?&gt;
  </code></pre>
  
  <p>This produces the following errors:</p>
  
  <blockquote>
    <p>[Tue Nov 22 12:57:51 2011] [error] [client ::1] PHP Warning:  fsockopen(): unable to connect to 127.0.0.1:8080 (Permission denied) in /usr/share/apache-tomcat-7.0.22/webapps/JavaBridge/java/Java.inc on line 994</p>
    
    <p>[Tue Nov 22 12:57:51 2011] [error] [client ::1] PHP Fatal error:  Uncaught Could not connect to the JEE server 127.0.0.1:8080. Please start it. Error message: Permission denied (13)\n\n  thrown in /usr/share/apache-tomcat-7.0.22/webapps/JavaBridge/java/Java.inc on line 989</p>
  </blockquote>
  
  <p>The steps I've taken to rule out problems are:</p>
  
  <ul>
  <li>Turned off firewall on the server</li>
  <li>Chmod'd everything to 777</li>
  <li>Checked that Tomcat is running before and after I run the PHP script (I assume, possibly wrongly, that Tomcat is the JEE server referred to in the second error message?) 
  4). PHP ini file has no open_basedir restrictions, safe mode is not on and the allow_furl_open and allow_url_include options</li>
  </ul>
  
  <p>I'm really stuck on this. No amount of Googling finds any similar specific problem. </p>
  
  <p>I must say that I'm very unfamiliar with Java and may have got the wrong end of the stick on the JavaBridge insofar as it may simply not be possible to run the java function from within the <code>/var/www/html</code> location and that any PHP scripts must be run from within the Tomcat JavaBridge app.</p>
  
  <p>I'm assuming that all the servlets are working but my lack of knowledge means I don't know to check that.</p>
  
  <p>As this is on Fedora could it be connected to a SELinux permissions issue?</p>