简体   繁体   English

Apache上php exec的权限和jar文件位置

[英]Permissions and jar file locations for php exec on apache

I'm setting up a small experiment on a Linux machine running MariaDB, Apache, Java and PHP... and after playing around all day with this and searching on this topic - I need some further clarification on some permissions and locations. 我正在运行MariaDB,Apache,Java和PHP的Linux机器上进行一个小型实验,并经过一整天的研究并搜索了这个主题-我需要进一步澄清一些权限和位置。 But let me first frame this: 但是,让我先构图一下:

In my web directory: /var/www/html I have a small test program: test.php. 在我的Web目录中:/ var / www / html我有一个小的测试程序:test.php。 It basically does this: 它基本上是这样做的:

<?php
    exec("java -jar MyApp.jar", $output);
    print_r($output);
?>

the MyApp.jar is a simple java application that connects to the local MariaDB and returns some useful information retrieved from the DB. MyApp.jar是一个简单的Java应用程序,它连接到本地MariaDB并返回从数据库中检索到的一些有用信息。

My main question is: where should my .jar files be and how do I make sure I execute the correct jar from php (how to reference it? full path?) and how/where/what else do I need to modify.... 我的主要问题是:我的.jar文件应该在哪里,如何确保从php执行正确的jar(如何引用它?完整路径?),以及我还需要如何/在何处/还需要修改什么... 。

EDIT: At the moment I'm going to put the files in: 编辑:目前,我要把文件放在:

/usr/share/httpd/

In the PHP code I'm going to refer to the full path: ie 在PHP代码中,我将引用完整路径:即

exec("java -jar /usr/share/httpd/MyApp.jar", $output);

In the interest of helping others - I also stumbled into a permission denied issue and needed to also do the following: 为了帮助他人-我也遇到了权限被拒绝的问题,还需要执行以下操作:

setsebool -P httpd_can_network_connect_db=1

I'd be interested in comments/answers on the security implications of having jar files in the /usr/share/httpd directory. 我对在/ usr / share / httpd目录中包含jar文件对安全性的意见/答案感兴趣。 Is there a better location? 有没有更好的位置? I need to ensure that these .jar files cannot be reached externally. 我需要确保无法从外部访问这些.jar文件。 I also am using the same directory for some jar libraries. 对于某些jar库,我也使用同一目录。

Install the JDK 安装JDK

Assume for this example that you wish to develop Java programs in addition to installing the JDK. 对于此示例,假设除了安装JDK外,您还希望开发Java程序。 Assume further that the current version of JDK is v1.7.0, and you want to automatically answer "yes" to all questions that the installation program asks. 进一步假设JDK的当前版本是v1.7.0,并且您想对安装程序提出的所有问题自动回答“是”。 Enter the following command at the CentOS command line: $ sudo yum install java-1.7.0-openjdk-devel -y 在CentOS命令行中输入以下命令:$ sudo yum install java-1.7.0-openjdk-devel -y

Set the JAVA_HOME environment variable 设置JAVA_HOME环境变量

Set JAVA_HOME to the location of JDK, which is /usr/lib/jvm/java-1.7.0-openjdk by default. 将JAVA_HOME设置为JDK的位置,默认情况下为/usr/lib/jvm/java-1.7.0-openjdk。 $ sudo sh -c 'echo export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk > /etc/profile.d/java.sh' $ source /etc/profile.d/java.sh $ sudo sh -c'echo export JAVA_HOME = / usr / lib / jvm / java-1.7.0-openjdk> /etc/profile.d/java.sh'$源/etc/profile.d/java.sh

Download Apache Tomcat 下载Apache Tomcat

Download the Tomcat binary. 下载Tomcat二进制文件。 The following command assumes that the current version of Tomcat is v7.0.56: $ wget http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar.gz 以下命令假定Tomcat的当前版本为v7.0.56:$ wget http://apache.mirrors.tds.net/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar 。广州

NOTE: Always check to ensure you are downloading the latest version. 注意:始终检查以确保您正在下载最新版本。 Version 7.0.56 was current at the time of writing. 在撰写本文时,版本7.0.56是最新的。

Unpack and configure 解压缩并配置

Unpack the binary file with the tar command: $ sudo tar xvzf apache-tomcat-7.0.56.tar.gz -C /opt 使用tar命令解压缩二进制文件:$ sudo tar xvzf apache-tomcat-7.0.56.tar.gz -C / opt

Make the unpacked files read-only; 将解压缩的文件设为只读; $ sudo chmod +r /opt/apache-tomcat-7.0.56/conf/* $ sudo chmod + r /opt/apache-tomcat-7.0.56/conf/*

Set CATALINA_HOME to the directory for the Tomcat files $ sudo sh -c 'echo export CATALINA_HOME=/opt/apache-tomcat-7.0.56 > /etc/profile.d/tomcat.sh' $ source /etc/profile.d/tomcat.sh 将CATALINA_HOME设置为Tomcat文件的目录$ sudo sh -c'echo export CATALINA_HOME = / opt / apache-tomcat-7.0.56> /etc/profile.d/tomcat.sh'$ source /etc/profile.d/ tomcat.sh

Start Tomcat 启动Tomcat

Run Tomcat's startup script. 运行Tomcat的启动脚本。 $ sudo $CATALINA_HOME/bin/startup.sh $ sudo $ CATALINA_HOME / bin / startup.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM