php 迁移 WordPress 网站后,我无法访问管理员(白页)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15557718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:28:36  来源:igfitidea点击:

After migration of WordPress website I can't access the admin (white page)

phpwordpresscontent-management-system

提问by AndreaNobili

I am trying to move a WordPress site from my local server to the online server.

我正在尝试将 WordPress 站点从我的本地服务器移动到在线服务器。

The problem is that, after the migration, if I try to open the administration page (wp-admin) I only obtain a white page, as you can see here: http://scorejava.com/wordpress/wp-admin/. Everything else seems work well in the homepage: http://scorejava.com/wordpress/.

问题是,在迁移之后,如果我尝试打开管理页面 (wp-admin),我只会获得一个白页,如您所见:http: //scorejava.com/wordpress/wp-admin/。主页中的其他所有内容似乎都运行良好:http: //scorejava.com/wordpress/

In my local web server I have the WP site into the folder: /var/www/wordpress. I have moved it into a wordpressfolder that is into my root directory of my online web server.

在我的本地 Web 服务器中,我将 WP 站点放入文件夹:/var/www/wordpress. 我已将其移动到一个wordpress文件夹中,该文件夹位于我的在线 Web 服务器的根目录中。

I have also import the local database into the onlyne database using MySql and then I have use the Search and Replace for WordPress Databases Scriptto change automatically all the http://localhost/wordpressoccurrence into the database tables with http://scorejava.com/wordpress/.

我还使用 MySql 将本地数据库导入到 onlyne 数据库中,然后我使用搜索和替换 WordPress 数据库脚本将所有http://localhost/wordpress出现的内容自动更改为http://scorejava.com/wordpress/的数据库表。

回答by Jon Surrell

There is an error on your site, and you need to find out what's happening.

您的网站出现错误,您需要了解发生了什么。

WordPress URLs

WordPress 网址

When migrating WordPress sites where the URL changes, you will need to tell WordPress about the new URL. WordPress stores that information in the database, so if you're comfortable with that, you could find the correct entry in the wp_optionstable in your database and update its value.

在迁移 URL 更改的 WordPress 站点时,您需要将新 URL 告知 WordPress。WordPress 将该信息存储在数据库中,因此如果您对此感到满意,您可以wp_options在数据库的表中找到正确的条目并更新其值。

I will show some fixes for standard WordPress installs (where the site URL is the WordPress root), but you mayneed to use different values for homeand siteurlif you have a different setup.

我将显示标准的WordPress安装(其中网站的网址是WordPress的根)一些修正,但您可能需要为使用不同的值home,并siteurl如果您有不同的设置。

Fix URLs via SQL

通过 SQL 修复 URL

You will need to update the relevant fields in the DB, those being the entries of wp_optionswhere the option_nameis siteurlor home. You can find these fields using phpmyadmin, mysql-workbench, or another database management tool, or you can use the following query, changing the URL to be your own.

您将需要更新的数据库相关的领域,这些是的条目wp_options,其中option_namesiteurlhome。您可以使用 phpmyadmin、mysql-workbench 或其他数据库管理工具找到这些字段,或者您可以使用以下查询,将 URL 更改为您自己的。

UPDATE `wp_options` SET `option_value`='http://www.myurl.com' WHERE `option_name` IN ('siteurl', 'home');

Fix URLs via wp-config.php

通过修复 URL wp-config.php

However, you can also do this via wp-config.php, which I find to be much more comfortable. Just open wp-config.phpand add the lines:

但是,您也可以通过 来执行此操作wp-config.php,我觉得这样更方便。只需打开wp-config.php并添加以下行:

// Site URLS (override DB settings)
define('WP_HOME','http://www.myurl.com');     //<-- NO TRAILING /
define('WP_SITEURL','http://www.myurl.com');  //<-- NO TRAILING /

Obviously you'll need to supply your correct URL.

显然,您需要提供正确的 URL。

It's possible that this is the only error you're having, and after adding those lines to wp-config.php, you will be able to log in and use your site normally.

这可能是您遇到的唯一错误,将这些行添加到 后wp-config.php,您将能够正常登录并使用您的站点。

Debugging WordPress errors

调试 WordPress 错误

However, if you continue to experience problems, and any time you're working on developing a website, you will want to see error output. You can check your server logs for information about the errors, but you may find it more convenient for WordPress to simply display the errors in the page. To enable error display, change the following setting to truein wp-config.php.

但是,如果您继续遇到问题,并且任何时候您正在开发网站,您都会希望看到错误输出。您可以检查服务器日志以获取有关错误的信息,但您可能会发现 WordPress 仅在页面中显示错误更方便。要启用错误显示,请将以下设置更改为truein wp-config.php

define('WP_DEBUG', true);

Now WordPress will display any errors it encounters directly in the webpage. Be sure to change the setting to falsefor use on a production site.

现在 WordPress 将直接在网页中显示它遇到的任何错误。请务必将设置更改false为在生产现场使用。

Working with wp-config.php

wp-config.php

This file will be located in the root directory of your wordpress installation. To make any of the changes mentioned here, you may either edit the file directly on the server (via sshfor example), or download the file with an FTP client, make your changes using a text editor, and upload the file again.

该文件将位于您的 wordpress 安装的根目录中。要进行此处提到的任何更改,您可以直接在服务器上编辑文件(ssh例如通过),或者使用 FTP 客户端下载文件,使用文本编辑器进行更改,然后再次上传文件。

It's also a good idea to keep a backup copy before making any changes in case you break something while you're working.

在进行任何更改之前保留备份副本也是一个好主意,以防您在工作时破坏某些内容。

References

参考

You can read all about changing the WordPress site URL on the docs page.

您可以在文档页面上阅读有关更改 WordPress 站点 URL 的所有信息。

回答by PHP Mentor

Late To the party, I've experienced this recently and I managed to solve the issue. Here is what I've done.

晚了,我最近经历了这个,我设法解决了这个问题。这是我所做的。

Step 1:Set WP_DEBUGto truefrom the wp-config.phpfile

第 1 步:从文件设置WP_DEBUGtruewp-config.php

Step 2:I tried domain.com/wp-login.phpinstead of domain.com/wp-adminby this I was able to get atleast login form and some errors of Warning: Cannot modify header information - headers already sent by

第 2 步:我尝试domain.com/wp-login.php而不是domain.com/wp-admin通过这个我能够获得至少登录表单和一些错误Warning: Cannot modify header information - headers already sent by

Step 3:I've added ob_start();in wp-login.phpfile after <?phpin first line, of course to get me in for a while.

第 3 步:我在第一行之后添加ob_start();wp-login.php文件<?php,当然是为了让我进入一段时间。

Step 4:This trick worked. I've disabled all the plugins, and errors are gone.

第 4 步:这个技巧奏效了。我已经禁用了所有插件,错误消失了。

Step 5:Activated all the plugins one by one to find which plugin is causing error, So that I can fix the error in particular plugin. Like there was one plugin adding style before wp_enqueque_styleso I set it to a function and hook it properly.

第五步:一一激活所有插件,找出哪个插件导致错误,以便我可以修复特定插件的错误。就像之前有一个插件添加了样式,wp_enqueque_style所以我将它设置为一个函数并正确挂钩。

There were some minor errors too like deprecatedfunctions. Its up to you whether you want to correct it or use alternate plugin.

也有一些小错误,比如deprecated函数。是否要更正它或使用备用插件取决于您。

And Don't forget to remove ob_startfrom wp_login.phpfile. The core files should not be changed.

并且不要忘记ob_startwp_login.php文件中删除。不应更改核心文件。

Hope this helps someone like me.

希望这可以帮助像我这样的人。

回答by webguy

Inside your settings for your WordPress dashboard there are two fields named "WordPress address (URL)" and "Site address (URL)". These are also known as the "Home" and the "Site URL" settings for your website. The values need to match the server you're actually running on.

在 WordPress 仪表板的设置中,有两个字段名为“WordPress 地址(URL)”和“站点地址(URL)”。这些也称为您网站的“主页”和“站点 URL”设置。这些值需要与您实际运行的服务器相匹配。

If you can't get to the admin, you can use phpmyadmin, go into your database, find the fields kin the wp_options table, and make sure they reflect your domain.

如果您无法访问管理员,您可以使用 phpmyadmin,进入您的数据库,找到 wp_options 表中的字段,并确保它们反映您的域。

It should be enough in most of cases.

大多数情况下应该足够了。

回答by cpilko

I've fought the dreaded "White Screen of Death" myself a few times. You can browse the threads at the Wordpress Support Siteto glean some suggestions, or Google it for lots and lots of people's stories and advice dealing with these. I can't recommend a single, authoritative reference for this.

我自己与可怕的“白屏死机”战斗了几次。您可以浏览Wordpress 支持站点上的主题以收集一些建议,或者在 Google 上搜索大量有关这些问题的故事和建议。我不能为此推荐单一的权威参考。

In most of my cases it was caused by whitespace after a closing ?>tag that got introduced because of changes in newline schemes between my dev and production servers, usually in a plugin.

在我的大多数情况下,这是由于?>我的开发服务器和生产服务器之间的换行方案发生变化而引入的结束标签之后的空格引起的,通常是在插件中。

You might also try putting Wordpress into debug modeor adding error_reporting(E_ALL);to the first line of your site's /wp-admin/admin.phpfile to see if these give you any hints.

您也可以尝试将 Wordpress 置于调试模式或添加error_reporting(E_ALL);到站点/wp-admin/admin.php文件的第一行,以查看这些是否会给您任何提示。

I've personally been able to avoid these (touch wood) by using the XCloner pluginto make transfers between my Win dev machine and *nix production server.

我个人已经能够通过使用XCloner 插件在我的 Win 开发机器和 *nix 生产服务器之间进行传输来避免这些(触摸木头)。

回答by Muhammad Awais Sarwar

Edit wp-content/themes/active-theme-folder/function.php and add this code just before:

编辑 wp-content/themes/active-theme-folder/function.php 并在之前添加以下代码:

<?php
define('WP_HOME','http://www.myurl.com');     //<-- NO TRAILING /
define('WP_SITEURL','http://www.myurl.com');

回答by Graham Davies

In many cases when migrating files to a different server this issue arises simply because of a minor error in one of your PHP files. The error is additional characters after the closing?> PHP tag in the file. These may just be simple whitespace or returns but they can often be the cause of the white screen of death.

在许多情况下,当将文件迁移到不同的服务器时,这个问题的出现仅仅是因为您的一个 PHP 文件中的一个小错误。错误是文件中关闭后的附加字符?> PHP 标记。这些可能只是简单的空白或返回,但它们通常可能是白屏死机的原因。

A primary culprit is the functions.php file in your WordPress theme. Take a look at it in a plain text file editor (often available with most hosting accounts) and ensure you delete any lines after the closing tag.

罪魁祸首是 WordPress 主题中的 functions.php 文件。在纯文本文件编辑器(通常适用于大多数托管帐户)中查看它,并确保删除结束标记后的所有行。

If it's not in this file use error reporting to identify the culprit file, it may be in a plugin or another file in your theme.

如果它不在此文件中,请使用错误报告来识别罪魁祸首文件,它可能在插件或主题中的另一个文件中。

As mentioned by Jon Surrell enable error display, change the following setting to true in wp-config.php.

正如 Jon Surrell 提到的启用错误显示,在 wp-config.php 中将以下设置更改为 true。

define('WP_DEBUG', true);

回答by Elenesski

I'm adding this answer to the fray, in the hope, it might help somebody else. I followed all of the advice above to no avail. I actually had to hack the PHP files to force my administrator to have access to the panel. It's through the panel that I discovered that my administrator account was not assigned the administrator role.

我正在将这个答案添加到争论中,希望它可以帮助其他人。我遵循了上述所有建议,但无济于事。我实际上不得不破解 PHP 文件以强制我的管理员访问面板。通过面板,我发现我的管理员帐户没有被分配管理员角色。

This is my hack to "wp-includes/capabilities.php"

这是我对“wp-includes/capabilities.php”的破解

function current_user_can( $capability ) {
    $current_user = wp_get_current_user();

    if ( empty( $current_user ) ) {
        return false;
    }

return true;  // HACK to get superuser power to any logged in user

    $args = array_slice( func_get_args(), 1 );
    $args = array_merge( array( $capability ), $args );

    return call_user_func_array( array( $current_user, 'has_cap' ), $args );
}    

This allowed the Administrator Panel to appear, with access to https://example.com/wp-admin/users.phpand then I could assign the role. I then unhacked the capabilities.php to ensure all users had the correct rights, now that I had "Administrator" assigned to me.

这允许管理员面板出现,可以访问https://example.com/wp-admin/users.php然后我可以分配角色。然后我取消了 capabilities.php 以确保所有用户都拥有正确的权限,因为我已经为我分配了“管理员”。

回答by para

I had the same problem after migrating to a local server. A first attempt failed because there were many hardcoded filepaths in the database. So I tried again and took care to create the same path as on the live server and the same hostname and databasename. Now the website was good but wp-login gave a white screen.

迁移到本地服务器后,我遇到了同样的问题。第一次尝试失败,因为数据库中有许多硬编码的文件路径。所以我再次尝试并注意创建与实时服务器上相同的路径以及相同的主机名和数据库名。现在该网站很好,但是 wp-login 出现了白屏。

With wp-debug I found that the problem was caused by wp-super-cache plugin that had a full filepath hardcoded in the config.php Changing this path to the full local path did the trick.

使用 wp-debug 我发现问题是由 wp-super-cache 插件引起的,该插件在 config.php 中硬编码了完整的文件路径,将此路径更改为完整的本地路径即可解决问题。

回答by Ganesan Murugesan

Add the below line into the wp-config.phpfile:

将以下行添加到wp-config.php文件中:

define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']);

define('WP_SITEURL', WP_HOME . '/');

回答by Paul De Jong

In you wp-config.php file just above the line stop editing line add this line:

在 wp-config.php 文件中,停止编辑行的正上方添加这一行:

define('RELOCATE',true);
/* That's all, stop editing! Happy blogging. */

Then go to your login URL, refresh the page and log in. IMPORTANT: If you can log in, then remove the RELOCATE line before preceding any further.Then navigate to:

然后转到您的登录 URL,刷新页面并登录。重要提示:如果您可以登录,请在进一步操作之前删除 RELOCATE 行。然后导航到:

Settings > General

Set your Wordpress URL and Site address to the correct locations:

将您的 Wordpress URL 和站点地址设置为正确的位置:

WordPress Address (URL): http://example.com/wordpress

Site Address (URL): http://example.com/myblog

Press "Save".

按“保存”。