简体   繁体   English

将 WordPress 多站点从本地主机迁移到公共主机(建立数据库连接时出错

[英]Migrate WordPress Multisite from localhost to public hosting (Error establishing a database connection

I'm a little desperate because I've been trying to find the problem I have for several days and there is no way.我有点绝望,因为这几天我一直在试图找到我遇到的问题,但没有办法。 I am new to WordPress but I have already developed several sites in PHP / Laravel.我是 WordPress 的新手,但我已经在 PHP / Laravel 开发了几个站点。

But I have created a WordPress Multisite website in local and when I try to publish it to my IONOS hosting, after doing everything that needs to be done, I get the error "Error establishing a database connection", it does not say anything else.但是我在本地创建了一个 WordPress 多站点网站,当我尝试将其发布到我的 IONOS 主机时,在完成所有需要完成的事情后,我收到错误“建立数据库连接时出错”,它没有说任何其他内容。 In the browser console I see also a very generic error (Failed to load resource: the server responded with a status of 500 ())在浏览器控制台中,我还看到一个非常普遍的错误(无法加载资源:服务器响应状态为 500 ())

The way to publish was as follows:发布方式如下:

  1. Create site generated by the same hosting IONOS with all the Multisite configuration done automatically by this site, adding the lines indicated in wp-config.php:创建由同一托管 IONOS 生成的站点,所有多站点配置由该站点自动完成,添加 wp-config.php 中指示的行:

    define( 'WP_ALLOW_MULTISITE', true );定义('WP_ALLOW_MULTISITE',真); define( 'MULTISITE', true );定义(“多站点”,真); define( 'SUBDOMAIN_INSTALL', false );定义('SUBDOMAIN_INSTALL',假); define( 'DOMAIN_CURRENT_SITE', 'xxxx' );定义('DOMAIN_CURRENT_SITE','xxxx'); define( 'PATH_CURRENT_SITE', '/' );定义('PATH_CURRENT_SITE','/'); define( 'SITE_ID_CURRENT_SITE', 1 );定义('SITE_ID_CURRENT_SITE',1); define( 'BLOG_ID_CURRENT_SITE', 1 );定义('BLOG_ID_CURRENT_SITE',1);

and in .htaccess:在 .htaccess 中:

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
  1. Delete the wp-content folder to upload the (wp-content) that I already have in local of the finished site.删除 wp-content 文件夹以上传我已经在完成站点本地的 (wp-content)。
  2. Edit wp-config changing the domain from 'localhost' to the domain of my hosting.编辑 wp-config 将域从“localhost”更改为我的托管域。
  3. Edit the .htaccess changing the "RewriteBase /" from local to hosting.编辑 .htaccess,将“RewriteBase /”从本地更改为托管。 5.In the database created by the hosting delete all the tables and import the database of the local site replacing the local domain by the new one in all the tables, starting with the wp-options tables and going through the posts, etc. tables. 5.在托管创建的数据库中删除所有表并导入本地站点的数据库,用所有表中的新域替换本地域,从 wp-options 表开始并遍历帖子等表. I have checked the PHP versions and they are 7.4 for my hosting and local, the WordPress version is also the same 5.8.我检查了 PHP 版本,我的主机和本地版本是 7.4,WordPress 版本也是 5.8。 The local DB version is MariaDB 10.4 and the hosting one is MySQL 5.7.本地数据库版本为 MariaDB 10.4,托管版本为 MySQL 5.7。 (It will be because of the version of BD????) (会不会因为BD的版本????)

I have checked everything a thousand times and I do not understand what can be happening, the database access credentials in the wp-config are correct, in fact I did the test with a script checking the DB connection in case the DB host does not work but the connection was made correctly.我已经检查了所有内容一千次,但我不明白会发生什么,wp-config 中的数据库访问凭据是正确的,事实上,我用脚本进行了测试,检查数据库连接,以防数据库主机无法正常工作但连接正确。

Can someone give me a hand?有人可以帮我吗?

WP will not connect to database, until you change hosts to IONOS. WP 不会连接到数据库,直到您将主机更改为 IONOS。

wp_site and wp_blogs tables must be edited to connect.必须编辑wp_sitewp_blogs表才能连接。

Use WP-CLI search-replace command.使用 WP-CLI搜索替换命令。

dry-run shows preview without changing values. dry-run显示预览而不更改值。

If local site is http do this first:如果本地站点是http ,请先执行此操作:

wp search-replace 'http://old.com' 'https://new.com' --all-tables --precise --dry-run

Then:然后:

wp search-replace 'old.com' 'new.com' --all-tables --precise --dry-run

Second command will change wp_site table and some options.第二个命令将更改wp_site表和一些选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM