Removing URL from Wordpress Database - wordpress

So I'm trying to clean up my development environment for my wordpress-based site. In the production site Wordpress database, there are thousands and thousands of references to the specific site URL.
For example, all of my permalinks have the full address. All of the images are referenced by their full address. All of the redirects are listed by their full address.
To clone my production database on a dev server, I have to:
Mysqldump the whole wordpress database into an sql file.
Search and replace all of the text for the production server domain name and replace with my dev server IP
Import the modified sql file into my dev db.
I'm clearly not doing something right.....
Suggestions on how I can get back on the right track?

Use this ( change tables prefix and domains at will ) :
/**
To update WordPress options with the new blog location, use the following SQL command:
**/
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
The last thing to do ( and only depends on your WP DB version ) is to verify in wp_options that home_urland blog_url have been replaced correctly .
Make sure the wp-config data is correct, ( including prefix ) and you are done .
I am doing this procedure at least 3 times a week in the last 3 years .. :-)

I've had the same problem, but got around it with a simple bash script:
#!/bin/sh
mysql -u«user» -p«password» «db-name» -e "update wp_options set option_value \
='http://dev.example.com' where option_value='http://www.example.com';"
It doesn't change every occurrence of the site's URL in the database, but it allows you to log in without being automatically redirected to the production site.
It works well enough for me anyhow. YMMV

I realize I'm raising this from the dead a little, but as there was no mention of this solution, I thought it important enough to make note of. We've been using this plugin for years with great success.
As opposed to hand-editing or other such pure-sql-based solutions, there exists the Duplicator plugin for Wordpress to allow for easy site migration of an existing site between live and devel and staging servers, though this basically packages up the entire site in a zip archive with an install script that walks you through the process and ensures the migration happens as cleanly as possible, along with follow up testing, logging of the process, etc.

Related

How to map or copy a wordpress site to a subfolder in an existing site's route?

I have a Wordpress blog (blog.xxx.com). I have a nuxt personal website yyy.com which is hosted on aws.
Now I wish to map or migrate the Wordpress blog (blog.xxx.com) to my personal site (yyy.com/blog).
How can we achieve this? yyy.com should show my personal site and yyy.com/blog should take you to my blog.
Can I configure this in Wordpress or what else can I do to achieve this?
I tried mapping it to a new domain, but I’m not sure how to map to a particular route and get it to work when I visit (yyy.com/blog/{blog-name}.
Yes, you can set up a WP site in a subfolder of your main website. I don't recommend doing it manually, too much can go wrong. Use a plugin such as Duplicator - it's so simple to use:
Install it on the site to copy and build a package - this packages your entire website into a single zip file
Copy this ZIP file and installer.php to the the hosting new location on your hosting (e.g. yyy.com/blog)
Create a new empty database
Run the installer wizard and make sure the URL in the new settings is https://www.yyy.com/blog
That's it!
You can have the entire site set up & running perfectly in just minutes! it will even set up .htaccess correctly.
No more setting up the database, changing urls in the database, 404 errors, broken links, broken images, etc. Moving a Wordpress site manually can be tricky and you can waste hours trying to fix the issues. Even agencies use a plugin to avoid the problems.
If I understood your question correctly, you want to move your WordPress installation from blog.xxx.com to yyy.com/blog, right?
There is an official guide for this provided by WordPress: https://wordpress.org/support/article/moving-wordpress/
After you have changed the siteurl and home fields in table wp_options of your database to yyy.com/blog, you can use a plugin like Better Search Replace (https://wordpress.org/plugins/better-search-replace/) that scans your WordPress database and replaces every URL of posts etc. with the new URL of your blog.
In addition, in case of an Apache webserver you need to take care of the .htaccess file and change the RewriteBase to /blog (assuming that it was / before).
Some special plugins (for caching etc.) need some special treatment, but often clearing the cache solves the problem.
Well despite Johannes is perfectly clear for me, i'll try to simplify.
Clone WordPress files from blog.xxx.com to yyy.com/blog directory. (not sure how your server is configured, but probably you'll be able to access it.)
Clone Database to new server.
Run sql replace queries:
UPDATE wp_options SET option_value = replace(option_value, 'https://blog.xxx.com', 'https://yyy.com/blog') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'https://blog.xxx.com','https://yyy.com/blog');
UPDATE wp_posts SET post_content = replace(post_content, 'https://blog.xxx.com', 'https://yyy.com/blog');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://blog.xxx.com','https://yyy.com/blog');
update your wp-config.php to match your new database.
login to yyy.com/blog/wp-admin
go to settings and update your permalinks

How do I bulk upload images coming from an old, defunct wordpress site to a new wordpress site?

Here is the situation: some friends had an old web site with wordpress running on it, and lost the domain name and hosting account through some shenanigans we won't discuss here. I have a full backup of their site, including a wordpress export file in XML.
I can easily create a completely new wordpress installation on their new server, using the export file to import all their posts into the database.
The problem is here: I can't use the importer to pull over the images and attachments using that XML file, because the links are incorrectly pointing to the now non-existant old site. I have the images and attachments, but now I'm wondering how can I bulk upload them into the new database's media library and maintain, or update, the links to them properly?
Scanning the wordpress support site and looking through the plugins list yields far too many hits that have nothing to do with what I am trying to accomplish.
I've tried modifying the export XML file to tell it to pull files from a local drive instead of the old host, by modifying attachment posts' <wp:attachment_url> entry, but this did not work. If someone knows what particular field the wordpress-importer is using, that would be quite a help, I think.
This will work only if , like you stated in your question - you have the FULL BACKUP of the site ( files AND database )
1 - FTP Put all the original wp folder structure from OLD site into NEW server as - is .
2 - login to phpmyadmin and import the OLD database .
3 - run SQL like so :
/**
To update WordPress options with the new blog location, use the following SQL command:
**/
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
Later , Just to verify , go to the wp_options ( or prefix_options ) table and search for home_url and blog_url options - and see if they are accordingly change ( this depends on DB version )
If all is ok and done correctly - you now can log in to your new domain..
BTW - If you have files and DB on local machine , you can run the changes, export and import to the DB already changed .. ( which is how I usually do it almost on a daily basis - a bit more time but fool proof )
If you do all the above correctly , and you did have the ORIGINAL DB and files exactly from before - you will have a new working copy on the new domain .
Basically, if you do that correctly , there is no need to "import" any images . you will be performing a simple move of domain for the whole site, including plugins, content, images, settings, themes and what not ..
Note on upgrades / version: when I wrote "original" wp folder structure I meant just that . even if it an old wp version and old plugins / themes - first do those steps above , and only then run an upgrade . Do not put a new wp version unless you know the old one is db compatible ...

Doubts about how to migrate WordPress from local to online server using Search and Replace Tool script

I am trying to migrate my blog from my local web server to an online web server and I have a doubt about this procedure.
I have uploaded all my local file in the root of my web server.
I have also export the tables of my local database (using phpMyAdmin) and I have import them on my online database.
Then I have change the settings inside the file wp-config.php in such a way as to make the connection with the online database.
Now I have to change the URL settings on my database using the Search and Replace Tool script: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/
So my doubts related to the use of the search and replace script are:
1) Have I to put the searchreplacedb2.php file into the root of my webserver (where it is the wp-config.php file) and have I to execute this script?
2) Have I to scann ALL the tables or only the posts table?
Tnx
Andrea
I do not know the script you have suggested , but what I always use is direct mysql queries like so :
/**
To update WordPress options with the new blog location, use the following SQL command:
**/
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
Note : something might have changed in the wp DB structure since I wrote this script , so just in case , after using it , goto wp_options table and double check the HOME and BLOG url entries to see they martch your new domain ..
A safer alternative may be to leverage wp-cli, specifically its search-replace function.
You can perform this operation to a local copy of the database, then upload that to your production environment.

When I move a WordPress blog, what do I have to change (database/file) to have the site test-run without changing the DNS?

i.e. http://xx.xx.x.xxx/wp-login.php redirects to blog at existing site www.my-blog.com
Maybe http://codex.wordpress.org/Moving_WordPress ?
And: to update WordPress options with the new blog location, use the following SQL command:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
It sounds like you're trying to move a Wordpress blog to a new host but you don't want to update the public DNS entry until you test it in its new location.
Many web server configurations use a single IP address that is used for multiple websites. The server figures out which site you want based on the name in the request.
So, to test your blog before updating the public DNS records, the easiest thing to do is edit your hosts file with the same change you will eventually make in DNS. This way, your own machine resolves the name to the new IP address but the rest of the world is still using the old one.
Here's info on the hosts file: http://en.wikipedia.org/wiki/Hosts_%28file%29
The most important two tables to update are the '_options' and '_posts' tables. Just do a SQL find and replace for your dev site URL and replace it with the live site URL. I always go through all tables with the find and replace to be safe, but those two tables should take care of most everything. (Obviously depending on your plugins this could change.)

Migrating Wordpress to another host: Can't login b/c it's confused about the host!

It's incredible!
I've just migrated a simple Wordpress site from my usual host to my client's host. The root directory for the site used to be http://www.imagineelection.com/watamu, and now it's http://www.watamuturtles.com
The http://www.watamuturtles.com homepage loads fine, but all of the links on the page still point to the old domain. Clearly I simply need to change a setting somewhere.
But -- I can't login to the admin interface! When I login at watamuturtles.org/login.php, it redirects me to the login page at imagineelection/watamu/login.php. And when I login at imagineelection, it swaps me back to watamuturtles.
Clearly I need to manually change the base directory setting in a config file, or in the database, without access to the usual WP admin interface. Can anyone point me in the right direction?
Tx!
~S
These 3 sql queries always does the trick for me when migrating:
fixing site url:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
fixing absolute urls:
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
fixing internal linking in your content:
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
Simple way to migrate WordPress: first change: WordPress address (URL) and Blog address (URL) in the old blog's settings, pointing them to new URL, then export database and them import it to new blog.
I found this post to be helpful too: Replace all fields in MySQL
I did the following steps:
Backup your database!
Search entire database in phpMyAdmin for "oldsite.com" - jot down which tables contain this string
Use the code in the response listed above to generate SQL queries for search and replace on all columns of each of the tables that get generated in the output (the code at the link above doesn't replace any text - just generates the SQL queries for you to execute to do the search/replace)
Run each SQL query that gets generated, which will actually replace the text

Resources