Create a wordpress test-system as a clone from productive system

For our WordPress-website, I wanted to create a test instance - to test WordPress-updates/plugin updates and new developments on the theme and so on ...

so i wrote a script to copy the database and the files:

sourcedir="/srv/www/htdocs/www.example.de"
testdir="/srv/www/htdocs/test.example.de"
workdir="/data/example.de_test-system"
sqldumpfile="$workdir/mysql_dump_example_wp2017.sql"

echo "delete webroot test.example.de"
rm -rf $testdir
echo "www.example.de nach test.example.de kopieren"
cp -R $sourcedir $testdir
echo "cache-verzeichnisse leeren"
rm -rf $testdir/wp-content/cache/minify
rm -rf $testdir/wp-content/cache/db
rm -rf $testdir/wp-content/cache/object
rm -rf $testdir/wp-content/cache/page_enhanced
rm -rf $testdir/wp-content/cache/tmp
echo "alten dump loeschen"
rm -f $sqldumpfile
echo "aktuellen Dump aus DB ziehen"
mysqldump -u root --password=xxx example_wp_2017  $sqldumpfile
echo "dump bearbeiten - www.example.de gegen test.example.de ersetzen"
sed -i s/www.example.de/test.example.de/g $sqldumpfile
echo "bearbeiteten dump in test-DB einspielen"
mysql -u root --password=xxx example_wp_2017_test  $sqldumpfile
echo "test-config einspielen"
cp /data/example.de_test-system/wp-config.php $testdir
echo "www-nutzer-rechte auf test.example.de setzen"
chown -R wwwrun $testdir
chgrp -R www $testdir

the script will copy the WordPress-folder, empty cache folders, dump the database and find/replace entries of the productive system with test-system and import the dump to the database - finally, copy the test-config to the test folder

this works, but I got some strange errors - like a logo image, where it displays a placeholder image instead

the meta-navigation is missing

and in the backend, some points in the left navigation are missing - like the custom post types

am I missing some things in my script?

Topic clone-site custom-post-types themes Wordpress

Category Web


I've found the best cloning plugin for my use is WP Clone here: https://wordpress.org/plugins/wp-clone-by-wp-academy/

Quite easy to use, just install on the source and target WP sites. Then export from the source site, and import to the target (log into the target). All your settings (including users) and content including media will be in the target site; you will have to log in using an account that was on the source system.

Great plugin.


In general test enviroments better use the same domain name as the live site. Since it doesn't seem like you follow such pattern (and yes, it is harder to follow), you need to make sure you convert all the URLs in the DB properly, and the way you do it will fail with any data which is serialized. Use wp-cli to change URLs instead of re-inventing your own solution.

In addition you will probably will want to change the option or add some code to make sure that google do not try to index the test site.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.