admin管理员组文章数量:1332604
I want to automatically clone mother website to subdirectory, which takes too much steps now and I think there would be easier way. Here's my steps I'm doing now
Make subdirectory site (add site) > install astro theme on subdirectory > delete sample pages and post > import mother site > change few things on cloned site (name etc..)
I think there would be easier way, Would be so nice to make it automatically. If you know any way please let me know! Thanks so much
I want to automatically clone mother website to subdirectory, which takes too much steps now and I think there would be easier way. Here's my steps I'm doing now
Make subdirectory site (add site) > install astro theme on subdirectory > delete sample pages and post > import mother site > change few things on cloned site (name etc..)
I think there would be easier way, Would be so nice to make it automatically. If you know any way please let me know! Thanks so much
Share Improve this question asked Jul 14, 2020 at 4:58 Shiny LeeShiny Lee 11 Answer
Reset to default 1I have done this exact thing so that I can test plugin updates. I wrote a shell script (bash) to create the sub directory and copy the files. Then, I leveraged WP-CLI commands to create wp-config file, export/import the database and search and replace the site name in DB. Here is my script with specifics changed to "yoursite"
#!/bin/bash
shopt -s expand_aliases
alias wp=~/bin/wp-cli.phar
wp --version
sourceDir=~/public_html
destDir=~/public_html/test/
### Delete existing files in $destDir
read -p "Deleting all files in $destDir ...Continue? (y/n): " -n 1 -r
echo
if [[ $REPLY = [yY] ]]; then
#rm -rf "$destDir/".[!.]* "$destDir/"*
rm -rf "$destDir"
mkdir "$destDir"
if [[ -z $(ls -A "$destDir") ]]; then
echo "Destination cleaned"
else
echo "Error: destination not empty"
exit 2
fi
else
echo "Script aborted by user"
exit 0
fi
### Clone source files
echo "Starting clone of source files"
cp "$sourceDir/"* "$destDir"
cp "$HOME/bin/.htaccess" "$destDir"
cp -R "$sourceDir/wp-"* "$destDir"
echo "Source files transfered"
### Create wp-config.php
cd "$destDir"
rm ./wp-config.php
wp config create \
--dbname=test_yoursite --dbuser=test_user --dbpass='yoursitePass' --dbprefix=wp_ --extra-php <<EOL
@ini_set('display_errors', 'Off');
@ini_set('log_errors', 'On');
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SAVEQUERIES', false);
define('WP_MEMORY_LIMIT', '1024M');
define('WP_POST_REVISIONS', 10);
define('WP_MEMORY_LIMIT', '128M');
define('WP_AUTO_UPDATE_CORE', 'minor');
EOL
### Clone DB and update site name
echo "Starting clone of Database"
cd "$destDir"
wp db export prod.sql --path="$sourceDir"
wp db reset --yes
wp db import prod.sql && rm -f prod.sql
wp option update siteurl http://test.yoursite
wp option update home http://test.yoursite
wp option update blogname 'Yoursite TEST'
echo "Searching and replacing domain name. Please wait this takes several minutes"
wp search-replace 'yoursite' 'test.yoursite' 'wp_posts'
wp rewrite flush
### Disable plugins
wp plugin deactivate w3-total-cache
wp plugin deactivate wordfence
echo "Done"
exit 0
There are also free or paid plugins such as Duplicator which can clone your site in a semi-automated fashion...possibly like you're already using.
There are also web hosting companies that include site cloning features (staging site); such as WP Engine, SiteGround and others.
本文标签: Automatically clone wordpress site to subdirectory
版权声明:本文标题:Automatically clone wordpress site to subdirectory 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742264615a2443152.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论