【问题标题】:Can't install/update plugin wordpress in macos local无法在 macOS 本地安装/更新插件 wordpress
【发布时间】:2018-08-14 02:26:09
【问题描述】:

我正在使用 macos 的默认 apache。我的 wp 网站无法安装新插件或更新插件。 但这在实时站点中正常工作。这些是我在尝试安装新插件时看到的列表错误:

错误提示:安装失败:内部服务器错误

按钮安装状态:更新失败!

在控制台调试中我看到:.../wp-admin/admin-ajax.php 500(内部服务器 错误)

我尝试搜索并以某些方式进行操作,例如:更改 chown,权限为 777,添加了 define('FS_METHOD', 'direct'),更改 memory_limit... 但是还是不行。

所以我经历了,当我在文件 .../wp-admin/includes/class-wp-upgrader.php 的第 450 行的 @set_time_limit( 300 ); 行中发表评论时,我看到它正在工作。但我不明白为什么会这样?

public function install_package( $args = array() ) {
    global $wp_filesystem, $wp_theme_directories;

    $defaults = array(
        'source' => '', // Please always pass this
        'destination' => '', // and this
        'clear_destination' => false,
        'clear_working' => false,
        'abort_if_destination_exists' => true,
        'hook_extra' => array()
    );

    $args = wp_parse_args($args, $defaults);

    // These were previously extract()'d.
    $source = $args['source'];
    $destination = $args['destination'];
    $clear_destination = $args['clear_destination'];

    //@set_time_limit( 300 ); **If I comment at here it's working**

    if ( empty( $source ) || empty( $destination ) ) {
        return new WP_Error( 'bad_request', $this->strings['bad_request'] );
    }
    $this->skin->feedback( 'installing_package' );
....
}

谁能建议我如何解决这个问题?

谢谢

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    为了保护网络服务器免受滥用,设置了 PHP 脚本可以运行的时间限制。例如,如果您的服务器收到 100 个没有时间限制的请求,它们可能会永远运行并占用整个 RAM。

    您本地机器的问题是插件安装的执行时间大于 300 秒(5 分钟)。可能是网速或 Apache 造成的。

    有 3 个选项可以修复它:

    选项 1:

    像你一样注释掉@set_time_limit( 300 );,但不要在生产时更新文件。

    选项 2:

    将此行添加到wp-config.php:

    ini_set('max_execution_time', 0);
    

    与选项 1 相同,因此不要在生产时更新文件。

    选项 3:

    使用更好的本地开发环境(推荐),例如VCCW

    【讨论】:

    • 感谢您的回答@Jared Chu,我刚刚尝试了“选项 2”,但它对我不起作用。关于选项 3 也许它可以帮助我,但我现在不想尝试,也许以后。现在我可以认为我的问题是在@set_time_limit(300) 之后无法执行任何代码。 /T
    • ini_set('max_execution_time', 0); 可能有效,但修改class-wp-upgrader.phpwp-config.php 没关系
    • 我不知道为什么,但是我通过将php从5.6升级到PHP 7解决了我的问题。所以我放在这里,如果有人有同样的问题可以试试。
    • 恭喜,我认为它行得通,因为 PHP7 有很好的性能
    猜你喜欢
    • 2016-09-16
    • 2019-07-09
    • 2021-09-06
    • 2020-05-19
    • 2013-08-13
    • 1970-01-01
    • 2018-01-21
    • 2017-03-10
    • 2014-03-19
    相关资源
    最近更新 更多