[英]php-fpm does not work exec, system, shell_exec, only CLI
php-fpm
, nginx
exec when in use .phpfiles()
shell_exec()
system()
works fine from the command line. php-fpm
, nginx
exec 在使用.phpfiles()
shell_exec()
system()
从命令行工作正常。
Example when works well:运行良好的示例:
#php myphp.php
myphp.php
contains: myphp.php
包含:
<?php
exec('ping -c 3 google.com', $output);
print_r($output);
?>
But if I put on my browser http://localhost/myphp.php
, it does not work anymore.但是如果我打开浏览器
http://localhost/myphp.php
,它就不再工作了。
Any ideas?有任何想法吗? I edit
我编辑
I made a file with the following contents:我制作了一个包含以下内容的文件:
#cat info.php
<?php
if(function_exists('exec')) {
echo "exec is enabled";
}
phpinfo();
?>
In my browser, print在我的浏览器中,打印
exec is enabled, y php info..
exec 已启用,y php 信息..
I made a file with the following contents:我制作了一个包含以下内容的文件:
#cat info.php
<?php
// Check for safe mode
if( ini_get('safe_mode') ){
// Do it the safe mode way
echo "Do it the safe mode way";
}else{
// Do it the regular way
echo "Do it the regular way";
}
?>
In my browser, print在我的浏览器中,打印
Do it the regular way
以常规方式进行
Did not I like to know if I'm in a jail?我不是想知道我是否在监狱里吗?
In my php ini在我的 php ini 中
#cat /etc/php-5.5.ini
safe_mode not shown, or ON or OFF.未显示安全模式,或者开启或关闭。 simply does not exist
根本不存在
I think exec and those kind of functions are disabled in your php.ini .我认为 exec 和那些功能在你的 php.ini 中被禁用。 You can check it by
你可以通过
if(function_exists('exec')) {
echo "exec is enabled";
} else {
echo "exec is disabled";
}
Open your php.ini and navigate to section disable_functions打开你的 php.ini 并导航到部分 disable_functions
If exec is listed under there , remove it.如果 exec 列在 there 下,请将其删除。
Then restart php-fpm
.然后重启
php-fpm
。
Also If Safe Mode is enabled this function will not be available.此外,如果启用了安全模式,则此功能将不可用。 You need to disable it.
你需要禁用它。
Edit编辑
use full path for ping.使用完整路径进行 ping。 You can find it by issuing this command in shell
which ping
您可以通过在 shell
which ping
发出此命令来找到它
Edit编辑
<?php
exec('/sbin/ping -c3 google.com', $output);
print_r($output);
?>
Php-fpm is chrooted by default on OpenBSD. PHP-fpm 在 OpenBSD 上默认是 chroot 的。 That's probably the cause you see it working on cli and not on web.
这可能是您看到它在 cli 上工作而不是在网络上工作的原因。
You've two solutions.你有两个解决方案。 Disable chroot (comment the line
chroot = /var/www
on /etc/php-fpm.conf
) or fix the issues you may encounter.禁用 chroot(注释
/etc/php-fpm.conf
上的chroot = /var/www
行)或修复您可能遇到的问题。
A static compiled version of ping resides under /bin/ping
(from inside the chroot). ping 的静态编译版本位于
/bin/ping
(来自 chroot 内部)。 You'll need to copy /etc/hosts
and /etc/resolv.conf
inside the chroot in order to resolv hosts names (as you're trying to do pinging google).您需要在 chroot 中复制
/etc/hosts
和/etc/resolv.conf
以解析主机名(因为您正在尝试 ping google)。 All other system commands you plan to call must be copied inside the chroot also (along with their shared libraries or compiled statically).您计划调用的所有其他系统命令也必须复制到 chroot 中(连同它们的共享库或静态编译)。
Use ldd(1)
to find out which libraries you'll need.使用
ldd(1)
找出您需要的库。 Depending on what you're trying to achieve it could be a tedious work.根据您要实现的目标,这可能是一项乏味的工作。
Exec, system and shell_exec are probably disabled, as other users pointed out.正如其他用户指出的那样,Exec、system 和 shell_exec 可能已被禁用。
<?php
//echo "Вот-вот... ещё 1 мин";
//echo "Wait... 1 min";
echo exec('/bin/bash --login -c "cd /var/www/194.7.2.2/public && /usr/local/rvm/rubies/ruby-2.5.3/bin/ruby work1.rb "'.$_GET['some_value']);
It`s worked 4me!它工作了 4me!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.