Support » Localhost Installs » Seperate files one DB

  • Hello, so I have one wordpress in server, and one locally. But I want to use remote database in my local wordpress. But the problem is that it always redirects me to the remote server as the site_url in database is from online version of wordpress. Is it possible somehow to define server url in php?
    I tried these but do not work. Also I have Multisite enabled.

    define(‘RELOCATE’,true);
    define(‘WP_HOME’,’http://example.com’);
    define(‘WP_SITEURL’,’http://example.com’);

Viewing 15 replies - 1 through 15 (of 18 total)
  • Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    The DB_HOST line of your wp-config.php file points to the database server.

    Yes, and it is pointing to remote database, but when I try opening website on my localhost I get redirected to that exact server. But how avoid redirecting but use same database is my question?

    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    You can dynamically set the URLs WP_HOME and WP_SITEURL

    See the first response at https://stackoverflow.com/questions/26014426/how-to-set-dynamic-home-and-siteurl-in-wordpress

    At least, I think that’s what you’re asking about.

    I have this in my wp-config:

    $base = ‘/’;
    define( ‘WP_ALLOW_MULTISITE’, true );
    define( ‘WP_HOME’, ‘http://localhost/mmo’ );
    define( ‘WP_SITEURL’, ‘http://localhost/mmo’ );
    define( ‘MULTISITE’, true );
    define( ‘SUBDOMAIN_INSTALL’, false );
    define( ‘DOMAIN_CURRENT_SITE’, ‘localhost’ );
    define( ‘PATH_CURRENT_SITE’, ‘/mmo/’ );
    define( ‘SITE_ID_CURRENT_SITE’, 1 );
    define( ‘ADMIN_COOKIE_PATH’, ‘/’ );
    define( ‘COOKIE_DOMAIN’, ” );
    define( ‘COOKIEPATH’, ” );
    define( ‘SITECOOKIEPATH’, ” );
    define( ‘NOBLOGREDIRECT’, ‘http://localhost/mmo’ );

    but I get: Error establishing a database connection

    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    Does your database allow remote connections? Check it’s config and the host’s firewall.

    Yes, remote connections are allowed this is simple picture of what I want to achieve. https://prnt.sc/juhp6t

    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    What is your DB_HOST line in each config? Also, does the DB_USER have permissions as DB_USER@localhost and DB_USER@yourotherservername?

    • This reply was modified 1 month, 1 week ago by  Steve Stern.

    define(‘DB_HOST’, ‘79.98.30.144’);

    • This reply was modified 1 month, 1 week ago by  duocia.
    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    How is the DB_USER defined on the DB server? Does it have a wild card as host?

    This is my connection lines, I know that connection works because, Because I made connection from my local phpmyadmin to remote database.

    define(‘DB_NAME’, ‘mmo’);

    /** MySQL database username */
    define(‘DB_USER’, ‘mmo’);

    /** MySQL database password */
    define(‘DB_PASSWORD’, ‘*****’);

    /** MySQL hostname */
    define(‘DB_HOST’, ‘79.98.30.144’);

    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    so, on your own PC

    mysql -u mmo -p***** -h 79.98.30.144 mmo

    works? If not, what error do you get?

    • This reply was modified 1 month, 1 week ago by  Steve Stern.

    Just a bit modified line 🙂
    https://prnt.sc/jui77h

    Without define( ‘MULTISITE’, true ) website works fine, but I cannot access other sites…

    • This reply was modified 1 month, 1 week ago by  duocia.
    • This reply was modified 1 month, 1 week ago by  duocia.
    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    Try a couple of things:

    1. define( 'DB_HOST', '79.98.30.144:3306' );

    and because I’m not sure about that

    2. in /etc/hosts (or wherever your hosts file might be), add
    79.98.30.144 mysql.remote.host, then use
    define( 'DB_HOST', 'mysql.remote.host' );

    I have Xampp, this should be in mysql config or apache?

    Moderator Steve Stern

    (@sterndata)

    Support Volunteer

    I don’t use XAMPP. You’ll have to check its documentation.

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