【问题标题】:"proc_open() has been disabled for security reasons" - PHP Error“出于安全原因,proc_open() 已被禁用” - PHP 错误
【发布时间】:2015-10-28 21:08:41
【问题描述】:

proc_open() 出于安全原因已被禁用

我目前正在免费托管 (Hostinger) - 制作个人网站仅供我和其他一些人使用。

我知道我应该从 php.ini 中删除 proc_open,但由于我的共享主机计划,我无法访问它。

我的代码中围绕proc_open 的代码如下 - 如果您需要完整代码,请告诉我。我试过注释掉部分,但它返回错误。

我只想删除它并让代码正常运行。

<?php
// Initializing
if (!isset($ACCOUNTS)) $ACCOUNTS = array();
if (isset($USER) && isset($PASSWORD) && $USER && $PASSWORD) $ACCOUNTS[$USER] = $PASSWORD;
if (!isset($HOME_DIRECTORY)) $HOME_DIRECTORY = '';
$IS_CONFIGURED = count($ACCOUNTS) >= 1 ? true : false;

// Command execution
function execute_command($command) {
    $descriptors = array(
        0 => array('pipe', 'r'), // STDIN
        1 => array('pipe', 'w'), // STDOUT
        2 => array('pipe', 'w')  // STDERR
    );

    $process = proc_open($command . ' 2>&1', $descriptors, $pipes);
    if (!is_resource($process)) die("Can't execute command.");

    // Nothing to push to STDIN
    fclose($pipes[0]);

    $output = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $error = stream_get_contents($pipes[2]);
    fclose($pipes[2]);

    // All pipes must be closed before "proc_close"
    $code = proc_close($process);

    return $output;
}

【问题讨论】:

  • 简单的答案是删除整个函数execute_command。在 Hostinger 的免费帐户上,您无权运行 shell 命令,并且可能永远不会被允许这样做
  • 是的,谢谢,我将在完成工作后搬到新的主机上。所以我可以删除整个命令,它会起作用吗?非常感谢。
  • 我不确定脚本是否会运行,如果它需要运行 shell 脚本...
  • 为什么你甚至需要在个人网站上运行 shell 命令?
  • 你们是如何解决这个问题的?

标签: php


【解决方案1】:

您可以尝试覆盖默认的 php.ini。以前用别的分享主机成功过,按此步骤操作

  1. 您在自己的 web 文件夹中创建自己的 php.ini。不需要在 php.ini 中具有所有值,只需要覆盖的内容即可。例如你的 php.ini 可能只有这样一行

    disable_functions = exec,execl,system,passthru,shell_exec,set_time_limit,escapeshellarg,escapeshellcmd,proc_close,ini_alter,proc_open,dl,popen,show_source,posix_getpwuid,getpwuid,posix_geteuid,posix_getegid,posix_getgrgid,open_basedir,safe_mode_include_dir,pcntl_exec,pcntl_fork,putenv,proc_get_status,proc_nice,proc_terminate,pclose,virtual,openlog,popen,pclose,virtual,openlog,escapeshellcmd,escapeshellarg,dl,show_source,symlink,eval,mail
    

记得从禁用函数中删除 proc_open

  1. 创建 .htaccess 并添加它

    <IfModule mod_suphp.c>
    suPHP_ConfigPath /home/user/public_html
    </IfModule>
    

记得用你的路径更改 /home/user/public_html

【讨论】:

  • 我尝试了相同的方法,但项目仍然存在问题。有没有其他方法可以解决。
【解决方案2】:

我通过编辑这个文件解决了我的问题 vendor->facade->ignition->config->flare.php 第 29 行

'collect_git_information' => true,  <---- Change this value to false

Laravel 6

PHP 7.3

【讨论】:

  • 设置collect_git_information false后你可以看到实际的错误,然后修复该错误,如果你保持laravel核心代码为原始,你可以再次将其设置为true
猜你喜欢
  • 1970-01-01
  • 2018-07-01
  • 2018-10-03
  • 2014-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
  • 1970-01-01
相关资源
最近更新 更多