Error establishing a database connection After Copy localhost wordpress site (with site url directly to hosting server’s url before copy)

Read http://codex.wordpress.org/Moving_WordPress#When_Your_Domain_Name_or_URLs_Change You’ve only moved the PHP files. That is only part of the process. Migrating the databse would mean: Create a database, if there isn’t one already Move the database from your local server to the remote one. Edit/alter key values in the database The same wp-config editing trick used here will get you … Read more

What’s a better workflow for database migration?

I use this for search and replace on databases – https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ Simply move files with FTP, export and import database and then run the script searching for old URL and replacing with the new URL. Then I resave permalinks and I’m done. I’ve moved WP thousands of times using this. I’ve got the old script … Read more

Migrate localhost to server

You can use the WP CLI too to rename your site’s hostname safely and effectively. There’s a chance that your layout is being messed up because naively replacing the domain name with a simple string replace, e.g. perl -pi -e ‘s/oldhost/newhost/g’ backup.sql, will not take into account things like serialized data. Try this on your … Read more

How can I assign post a specific ID on creation?

Yes, use the “import_id” field in the post, when calling wp_insert_post. This is treated as a “suggested” ID for the post that will be used if no post with that ID already exists. $post = array( ‘post_title’=>’whatever’, ‘post_content’=>’whatever’, ‘import_id’=>123 ); wp_insert_post($post);

URLs to images get messed up after migration

Back up your database (this is very very important) and download and install “Velvet Blues Update URLs” plugin. On the settings page enter in the old URL field http://subdomain.domain.com/subdomain.domain.com Enter in the new URL field the URL of your website. Select all options and click “Update”. Update your permalinks as well.

How to upload local changes to a live server without overriding new posts/pages?

Making content (database) changes on a staging environment is never recommended. You should only use a local/staging environment for template changes. Then, update your theme/plugins (the wp-content folder), and push those files to the live site. Once that’s completed, you can then populate the content. Database merging/synchronization is it’s own specialty/portion of the industry, and … Read more

Export and overwrite pages on import?

You have a narrow selection to choose from. Either replace the database tables with something like wp-cli or have a special import-export process for your data. If you want to make this granular, you could make a post metabox to import/export post content and metadata as json. Then updates could be incremental and on the … Read more