• Hello everybody I am struggling every time I have to export a database from my local server on my PC (using xampp) to my production server (linux Centos7)

    the database from my local contains all referrers like https://localhost while in the production site they must be https://www.mysite.com
    I have tried 2 find and replace plugins but when the database is big they are crashing before the job is done.
    I would prefer to do all work on a shell environment using command line as it goes much quicker…
    I have also installed wp-cli and now I am testing with it but the find and replace command is not clear: wp search-replace “https://old-url.com”” “https://new-url.com””
    where and what database will be searched running this command which is give by wp instructions?

    What is the best way to solve this migration issue?
    Thank you

    • This topic was modified 2 years, 1 month ago by papacico.
    • This topic was modified 2 years, 1 month ago by papacico.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Yui

    (@fierevere)

    永子

    Migration plugins usually handle export and replacing domain in the database very well.

    i.e. Duplicator

    It is not recommended to do direct replace in the database dump or with SQL query,
    because some settings are stored in the serialized arrays and they will break.

    You can also use this 3rd party PHP script: https://github.com/interconnectit/Search-Replace-DB/releases

    Thread Starter papacico

    (@papacico)

    thank you will check the php script

    eagerbob

    (@eagerbob)

    I use the free WP-SYNC-DB plugin, which can do a find and replace so you can change your old URL into the new one. It can do big databases and the images too with an optional media-library extension. It can push (from local to remote) or pull (from remote) and it saves your settings so it becomes an easy process.

    https://wp-sync-db.github.io

    • This reply was modified 2 years ago by eagerbob.

    What @eagerbob said. Hasn’t let us down for years. Direct link to repo: https://github.com/wp-sync-db

    Hi, the drawback of using a search and replace plugin for the database is that you can get as a result an inconsistent or corrupted database. For that reason always do a backup first. Many plugins serialize their data in a different way, thus a simple search and replace will not always work.

    The best solution is to add an entry to the hosts file before you start developing your WordPress website in local. On Linux the path is /etc/hosts. On windows, C:\Windows\system32\drivers\etc\hosts. You have to edit the file as an administrator. For example, add this entry:
    127.0.0.1 mydomainame.com

    Doing this you don’t need to do any kind of search and replace in the future.

    Another trick is to replace all strings localhost with your domain just before the output is returned to the user. This is the trick:

    
    add_action( 'muplugins_loaded', 'wp_replace_domain_buffer_start' );
    add_action( 'shutdown', 'wp_replace_domain_buffer_end' );
    
    // functions
    function wp_replace_domain_buffer_start { ob_start( 'wp_replace_domain_buffer_replace' ); }
    function wp_replace_domain_buffer_end { @ob_end_flush(); }
    
    function wp_replace_domain_buffer_replace( $buffer ) {
        return str_replace( array( '127.0.0.1:8000', 'mydomain.com' ), $buffer );
    }

    I am choosing the hook muplugins_loaded because it’s the first hook to execute WordPress.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exporting database from test to production’ is closed to new replies.