At the very beginning download the latest wp-cli
Code: Select all
wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp
chmod +x /usr/local/bin/wp
Code: Select all
cd /home/someMyVestaUser/web/new-domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN='old-domain.com'
TO_DOMAIN='new-domain.com'
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
Code: Select all
cd /home/someMyVestaUser/web/new-domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN="http://localhost:8081"
TO_DOMAIN="https://new-domain.com"
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
Code: Select all
cd /home/someMyVestaUser/web/new-domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN='old-domain.com/subdomain'
TO_DOMAIN='new-domain.com'
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
Some plugins put backslashes in URLs, so if something is still pointing to the old domain, then try this search:
Code: Select all
cd /home/someMyVestaUser/web/new-domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN="http:\\/\\/old-domain.com"
TO_DOMAIN="http:\\/\\/new-domain.com"
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
Code: Select all
FROM_DOMAIN="http:\\/\\/old-domain.com\\/subfolder"
TO_DOMAIN="http:\\/\\/new-domain.com"
Example of replacing non-www to www:
Code: Select all
cd /home/someMyVestaUser/web/domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN='https://domain.com'
TO_DOMAIN='https://www.domain.com'
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
FROM_DOMAIN='http://domain.com'
TO_DOMAIN='http://www.domain.com'
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"
Example of replacing www to non-www:
Code: Select all
cd /home/someMyVestaUser/web/domain.com/public_html/
USER='someVestaUser'
FROM_DOMAIN='www.domain.com'
TO_DOMAIN='domain.com'
sudo -H -u$USER wp search-replace "$FROM_DOMAIN" "$TO_DOMAIN" --precise --all-tables --skip-columns=guid
sudo -H -u$USER wp cache flush
grep -rl "$FROM_DOMAIN" ./ | xargs sed -i "s#$FROM_DOMAIN#$TO_DOMAIN#g"