In the following information, we work with a MySQL database. We deals with the case of changing nicodevlog.com to codetodevops.com.
I wrote this article after I changed nicodevlog.com to codetodevops.com
Backup your database
Firstly, make a backup of your database. If you have a mysql or postgresql database, your backup will be a file that contains all the SQL instruction to create and fill your database.
You can make a backup with your hosting or with a command line if you have access to the server that hosts your website.
Search and replace in your database backup file
If you don’t have notepad++ you download and install it.
If you “search and count” yourdomain.com (for instance nicodevlog.com), you’ll find thousands of occurencies.
Just search and replace yourdomain.com by your new domain name will work only if they have a the same number of letters, because some wordpress data are serialized under the following form:
s:14:\”nicodevlog.com\”
s:14 indicate the number of letters in the following string, then if you search and replace nicodevlog.com by codetodevops.com it will be incorrect to have s:14:\”codetodevops.com\”. The correcte serialized would look like s:16:\”codetodevops.com\”.
Then in this case, if your new domain name doesn’t have the same number of letters you should use an existing php script. I downloaded the following script at https://interconnectit.com/search-and-replace-for-wordpress-databases/
This script manage the serialization of data.
Your wordpress theme is looking for file name that contains you newdomain name?
Now that you have done this, maybe you will encounter problem with some images in your wordpress theme. In my case I found out that the header background was not found (404 error) because my wordpress theme was looking for images name with “codetodevops” in the file name instead of nicodevlog.
To correct this you cas go inside your web site directory and execute the following script:
for f in $(find ./ -name *nicodevlog*.jpg); do cp $f $(echo “$f” | sed s/nicodevlog/codetodevops/); done
it duplicates file that contain the name nicodevlog for instance header_nicodevlog_widesize.jpg, and it duplicates it in header_codetodevops_widesize.jpg
Leave a Reply