PHP JavaBridge权限错误

发布于 2024-12-17 08:58:08 字数 2506 浏览 5 评论 0原文

我有一个现有的大型 PHP Web 应用程序(使用 Apache 和 MySQL),它现在需要能够调用基于 Java 的报告引擎。因此,我想要实现的是从现有 PHP 应用程序中访问 java 类的能力。

到目前为止,在新的开发服务器上,我已经成功安装了开源 PHP-Javabridge 项目 (http://php-java-bridge.sourceforge.net/pjb/index.php) 并让它在 Tomcat (7.0.1) 下运行。 22) 在使用端口 8080 的 Fedora 15 机器上。由于实时系统的托管限制,我无法使用 Zend Javabridge,不幸的是,目前无法选择更改提供程序。

我还使用端口 80 在开发盒上运行 Apache 和 PHP。

我可以访问 Tomcat 中的 JavaBridge Web 应用程序,并且所有 PHP 示例都运行良好。但是,当我尝试从现有应用程序中访问 JavaBridge 时,我遇到了问题。

我假设我应该可以从位于 Apache Web 根目录 (/var/www/html) 的脚本中调用 php 'java' 函数。

我使用了 JavaBridge 应用程序中提供的脚本,如下所示:

<?php
    require("http://127.0.0.1:8080/JavaBridge/java/Java.inc");
    echo java("java.lang.System")->getProperties();
?>

这会在 /etc/httpd/logs/error_log 中产生以下错误

[2011 年 11 月 22 日星期二 15:01:08] [错误] [客户端 ::1] PHP 警告:require_once(http://localhost:8080/JavaBridge/java/Java.inc):无法打开流: /var/www/html/javatest.php 第 2 行的权限被拒绝

[2011 年 11 月 22 日星期二 15:01:08] [错误] [客户端 ::1] PHP 致命错误:require_once():无法打开所需的 'http://localhost:8080/JavaBridge/java/Java.inc ' (include_path='.:/php/includes:/usr/share/apache-tomcat-7.0.22/webapps/JavaBridge') 在/var/www/html/javatest.php 第 2 行

另一个建议的脚本是:(注意:我在 /var/www/html 中有一份 Java.inc 的副本)

<?php
    define("JAVA_HOSTS", "127.0.0.1:8080");
    define("JAVA_SERVLET", "/JavaBridge/servlet.phpjavabridge");
    require_once("./Java.inc");
    echo java("java.lang.System")->getProperties();
?>

这会产生以下结果错误:

[Tue Nov 22 12:57:51 2011] [error] [client ::1] PHP 警告:fsockopen():无法连接到 /usr/share/apache 中的 127.0.0.1:8080(权限被拒绝) -tomcat-7.0.22/webapps/JavaBridge/java/Java.inc 第 994 行

[2011 年 11 月 22 日星期二 12:57:51] [错误] [客户端 ::1] PHP 致命错误:未捕获 无法连接到 JEE 服务器 127.0.0.1:8080。请开始吧。错误消息:权限被拒绝 (13)\n\n 在 /usr/share/apache-tomcat-7.0.22/webapps/JavaBridge/java/Java.inc 第 989 行抛出

我为排除问题所采取的步骤是:

  • 关闭服务器上的防火墙
  • 将所有内容更改为 777
  • 在运行 PHP 脚本之前和之后检查 Tomcat 是否正在运行(我假设,可能是错误的,Tomcat 是第二个中提到的 JEE 服务器) 错误信息?) 4). PHP ini 文件没有 open_basedir 限制,安全模式未打开,并且allow_furl_open 和allow_url_include 选项

我真的很困惑。无论进行多少次谷歌搜索都找不到任何类似的具体问题。

我必须说,我对 Java 非常不熟悉,并且可能在 JavaBridge 上搞错了方向,因为它可能根本不可能从 /var/www/html< 中运行 java 函数。 /code> 位置,并且任何 PHP 脚本都必须从 Tomcat JavaBridge 应用程序中运行。

我假设所有 servlet 都在工作,但我缺乏知识意味着我不知道要检查这一点。

由于这是在 Fedora 上,它是否可能与 SELinux 权限问题有关?

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.

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.

I also have Apache and PHP running on the dev box using port 80.

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.

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

I have used the script supplied in the JavaBridge application as follows:

<?php
    require("http://127.0.0.1:8080/JavaBridge/java/Java.inc");
    echo java("java.lang.System")->getProperties();
?>

This produces the following errors in /etc/httpd/logs/error_log

[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

[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

The other suggested script is: (note: I have a copy of Java.inc in /var/www/html)

<?php
    define("JAVA_HOSTS", "127.0.0.1:8080");
    define("JAVA_SERVLET", "/JavaBridge/servlet.phpjavabridge");
    require_once("./Java.inc");
    echo java("java.lang.System")->getProperties();
?>

This produces the following errors:

[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

[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

The steps I've taken to rule out problems are:

  • Turned off firewall on the server
  • Chmod'd everything to 777
  • 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

I'm really stuck on this. No amount of Googling finds any similar specific problem.

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 /var/www/html location and that any PHP scripts must be run from within the Tomcat JavaBridge app.

I'm assuming that all the servlets are working but my lack of knowledge means I don't know to check that.

As this is on Fedora could it be connected to a SELinux permissions issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

肤浅与狂妄 2024-12-24 08:58:08

Narcissus - 非常感谢您的意见,但事实证明这是 SELinux 的权限问题,导致 PHP 无法调用 JavaBridge。

我通过以 root 用户身份发出以下命令来暂时解决了这个问题:

setenforce 0

我需要找到一个更令人满意的长期解决方案来更改 SELinux 权限以允许 PHP 和 Javabridge 之间的交互,但这是一个不同的问题。 。

Narcissus - many thanks for your input, but it turned out to be a permissions issue with SELinux which was preventing PHP from making the call to the JavaBridge.

I have temporarily solved the issue by shutting off SELinux by issuing the following command as root user:

setenforce 0

I need to find a more satisfactory long term term solution to alter SELinux permissions to allow the interaction between PHP and Javabridge but that is a different issue...

红尘作伴 2024-12-24 08:58:08

您是否在 php.ini 中添加了此代码?

allow_url_include = On

Did you add this code in your php.ini?

allow_url_include = On
旧城烟雨 2024-12-24 08:58:08

我在设置 PHP Java Bridge 时也遇到了一些问题。不过,查看我的设置,我发现 JAVA_HOSTS 定义为 127.0.0.1:8087。

如果您的浏览器能够在该端口上看到某些内容,但桥接连接仍然无法工作,则可能是侦听应用程序未正确侦听。

如果您访问 php-java-bridge.sourceforge.net/pjb/desktop-apps.php 并按照“将 PHP/Java Bridge 库添加到您的 Java 应用程序”中的粗体代码部分进行操作,您会发现您需要:

  • 将 JavaBridge.jar 文件添加到您的项目中
  • 添加 public static final String JAVABRIDGE_PORT="8087"; 到您的类中
  • 添加 static final php.java.bridge.JavaBridgeRunner 类
  • runner = php.java.bridge.JavaBridgeRunner.getInstance(JAVABRIDGE_PORT); 到主函数中的

,调用 runner.waitFor();这基本上会将您的应用程序设置为监听。

I had some problems with the PHP Java Bridge too while setting it up. Looking in my setup, though, I see that I have JAVA_HOSTS defined as 127.0.0.1:8087.

If your browser is able to see something on that port but the bridge connection still doesn't work, it could be that the listening app is not listening correctly.

If you go to php-java-bridge.sourceforge.net/pjb/desktop-apps.php and follow the bolded sections of code in the 'Add the PHP/Java Bridge library to your Java application' you can see that you need to:

  • add the JavaBridge.jar file to your project
  • add public static final String JAVABRIDGE_PORT="8087"; to your class
  • add static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner.getInstance(JAVABRIDGE_PORT); to your class
  • in your main function, call runner.waitFor();

That will basically set your application up to listen.

千里故人稀 2024-12-24 08:58:08

为了给其他人一个偶然发现这个问题的额外故障排除选项——这对我有用:

sudo setsebool -P httpd_can_network_connect_db=1

这使得 SELinux 允许 apache 连接到你的数据库。我收到如下错误:

httpd 错误日志:

java.sql.SQLNonTransientConnectionException: .... 权限被拒绝。
引起原因:java.net.SocketException:权限被拒绝

In the interest of giving others an extra trouble shooting option that stumble across this -- this worked for me:

sudo setsebool -P httpd_can_network_connect_db=1

This enables SELinux to allow apache to connect to your database. I was getting errors like this:

httpd error log:

java.sql.SQLNonTransientConnectionException: .... Permission Denied.
Caused by: java.net.SocketException: Permission denied

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文