Support » Fixing WordPress » Migrate WordPress Multisite from localhost to public hosting (Error establishing

  • 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.

    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. In the browser console I see also a very generic error (Failed to load resource: the server responded with a status of 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:

    define( 'WP_ALLOW_MULTISITE', true ); define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', false ); define( 'DOMAIN_CURRENT_SITE', 'xxxx' ); define( 'PATH_CURRENT_SITE', '/' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 );

    and in .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]

    2.Delete the wp-content folder to upload the (wp-content) that I already have in local of the finished site.
    3. Edit wp-config changing the domain from ‘localhost’ to the domain of my hosting.
    4.Edit the .htaccess changing the “RewriteBase /” from local to hosting. 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. 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. The local DB version is MariaDB 10.4 and the hosting one is MySQL 5.7. (It will be because of the version of 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.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Check your db connection strings in your wp-config.php file at the root of your site.
    And check the table prefix constant in that same file. Make sure the tables in the db you trying to connect to has the same prefix.

    https://digwp.com/2010/10/change-database-prefix/

    Topher

    (@topher1kenobe)

    Look in your file system for some other wp-config files. They can have names like wp-config-local.php and they can also be above your docroot and still function. I know you’re not Pantheon, but they can have one called wp-config-pantheon.php. So look and see what’s in there and prune out what you don’t need.

    Thread Starter oscar87

    (@oscar87)

    Hi @corrinarusso thanks for reply, yes, the prefix of the tables in the database corresponds to the one I have configured in the wp-config file using the line “$table_prefix = …”

    Thread Starter oscar87

    (@oscar87)

    Hi @topher1kenobe , thanks for your reply, i had a file called “wp-config-sample.php” i have tried removing this file but the error persists.

    Topher

    (@topher1kenobe)

    Let’s try to see if your wp-config.php file is being used at all. Try putting

    exit;

    in the top of it and load the page. If it gives you a white screen then it’s using your file. If nothing changes then it’s using some other file.

    Thread Starter oscar87

    (@oscar87)

    Yes, @topher1kenobe i´ve tried exit; and I get a completely white screen!!

    Topher

    (@topher1kenobe)

    Ok, that means it’s using that wp-config file, and your credentials in there are wrong.

    Thread Starter oscar87

    (@oscar87)

    Ok, @topher1kenobe, thanks!!

    I do not understand because it is an installation created by the hosting provider, which worked and connected to the database with those connection parameters. Then the only thing I changed is the wp-content folder and the content of the database without changing the name of the database.
    Changind url in the database, the new prefix in wp-config…

    Thread Starter oscar87

    (@oscar87)

    in fact I put the following script in the wp-config file, with the corresponding connection parameters, and the response is that the connection has been established correctly

    <?php
      $host_name = 'xxxx';
      $database = 'xxxx';
      $user_name = 'xxxxx';
      $password = 'xxxxx';
    
      $link = new mysqli($host_name, $user_name, $password, $database);
    
      if ($link->connect_error) {
        die('<p>Error al conectar con servidor MySQL: '. $link->connect_error .'</p>');
      } else {
        <strong>echo '<p>Se ha establecido la conexión al servidor MySQL con éxito.</p>';</strong>
      }
    ?>
    • This reply was modified 1 month, 2 weeks ago by oscar87.

    Then the only thing I changed is the wp-content folder and the content of the database without changing the name of the database

    .

    ???
    What do you mean you changed the wp-content folder?

    Changind url in the database

    You changed the url in the _options table of the database?

    Thread Starter oscar87

    (@oscar87)

    Hi, @corrinarusso
    Yes, I saw in some tutorials that an easier way to move from localhost to public hosting was to generate the site through the hosting service which creates everything with the multisite network included and that after creating it, all you have to do is delete the wp-content folder and upload the wp-content of the site created locally. And the same with the database, delete all the tables and import the tables of the local DB of the site already created, that’s why you have to change the url too (from localhost to dominiopublico).
    I don’t know if there are other safer options.
    Before this I tried publishing all the sources and DB and I got the same DB connection error.

    Translated with http://www.DeepL.com/Translator (free version)

    Hi @oscar87

    Yes, okay. All this process is correct.

    Hmmmm. Not sure where else to go here.
    – you’ve verified the connection strings in the wp-config are valid
    – you’ve changed the siteurl and sitehome URL in the _options table
    – you’ve verified that the table_prefix in the wp-config file are correct

    Can you check your htaccess file?

    htaccess

    htaccess

    Thread Starter oscar87

    (@oscar87)

    Yes @corrinarusso, i´ve checked .htaccess file too, it was generated by hosting service and it matches with the example in the link that you tell me about.

    I don’t know what to try anymore…

    At this point, I would uninstall the instance of WordPress you have installed, and start over.

    I would also recommend using a migration tool like this:
    https://wpmayor.com/migrate-wordpress-multisite/

    You have everything local, so it should only take 10 mins to uninstall, and reinstall using the cpanel tools.

    Also, have you already looked at the PHP errors logs on the server?

Viewing 14 replies - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.