更新时间:2023-01-31 20:12:00
我想有一个目录的地方称为脚本的WWW文件夹下,这样它不是从网站访问,但访问是由PHP。
I would have a directory somewhere called scripts under the WWW folder so that it's not reachable from the web but is reachable by PHP.
例如。 /无功/网络/脚本/ testscript
请确保用户/组为您 testscript
是与您的webfiles。举例来说,如果你的 client.php
是拥有阿帕奇:阿帕奇
,改变bash脚本到同一个用户/组使用 CHOWN
。你可以找出你的是什么 client.php
和网页文件做 LS -al
拥有。
Make sure the user/group for your testscript
is the same as your webfiles. For instance if your client.php
is owned by apache:apache
, change the bash script to the same user/group using chown
. You can find out what your client.php
and web files are owned by doing ls -al
.
然后运行
<?php
$message=shell_exec("/var/www/scripts/testscript 2>&1");
print_r($message);
?>
编辑:
如果你真的想从网络服务器上运行一个文件作为根你可以试试下面这个二元包装。看看这个解决方案,你想要做同样的事情。
If you really want to run a file as root from a webserver you can try this binary wrapper below. Check out this solution for the same thing you want to do.
通过PHP 执行根命令