Transferring WordPress to a local instance for development and testing
Install PHP Composer
https://getcomposer.org/download
Install wp-cli
composer global require wp-cli/wp-cli-bundle
apt-get install less
Run search and replace
cd /var/www/html # or whatever your WordPress site root is
/home/myuser/.composer/vendor/bin/wp search-replace 'https://example.com.au' 'http://example.internal' --all-tables
# when you copy your site back to the internet reverse the arguments
/home/myuser/.composer/vendor/bin/wp search-replace 'https://example.internal' 'http://example.com.au' --all-tables
Example output
/home/myuser/.composer/vendor/bin/wp search-replace 'https://example.com.au' 'http://example.internal' --all-tables
+-------------------------------------+-----------------------+--------------+------+
| Table | Column | Replacements | Type |
+-------------------------------------+-----------------------+--------------+------+
| wp_tgnotk_commentmeta | meta_key | 0 | SQL |
| wp_tgnotk_commentmeta | meta_value | 4 | PHP |
| wp_tgnotk_comments | comment_author | 0 | SQL |
| wp_tgnotk_comments | comment_author_email | 0 | SQL |
| wp_tgnotk_comments | comment_author_url | 124 | SQL |
| wp_tgnotk_comments | comment_author_IP | 0 | SQL |
| wp_tgnotk_comments | comment_content | 8 | SQL |
| wp_tgnotk_comments | comment_approved | 0 | SQL |
| wp_tgnotk_comments | comment_agent | 0 | SQL |
| wp_tgnotk_comments | comment_type | 0 | SQL |
| wp_tgnotk_ig_caticons | icon | 0 | SQL |
| wp_tgnotk_ig_caticons | small_icon | 0 | SQL |
| wp_tgnotk_links | link_url | 1 | SQL |
| wp_tgnotk_links | link_name | 0 | SQL |
| wp_tgnotk_links | link_image | 0 | SQL |
| wp_tgnotk_links | link_target | 0 | SQL |
| wp_tgnotk_links | link_description | 0 | SQL |
| wp_tgnotk_links | link_visible | 0 | SQL |
| wp_tgnotk_links | link_rel | 0 | SQL |
| wp_tgnotk_links | link_notes | 0 | SQL |
| wp_tgnotk_links | link_rss | 0 | SQL |
| wp_tgnotk_options | option_name | 0 | SQL |
| wp_tgnotk_options | option_value | 10 | PHP |
| wp_tgnotk_options | autoload | 0 | SQL |
| wp_tgnotk_postmeta | meta_key | 0 | SQL |
| wp_tgnotk_postmeta | meta_value | 64 | PHP |
| wp_tgnotk_posts | post_content | 3575 | SQL |
| wp_tgnotk_posts | post_title | 0 | SQL |
| wp_tgnotk_posts | post_excerpt | 0 | SQL |
| wp_tgnotk_posts | post_status | 0 | SQL |
| wp_tgnotk_posts | comment_status | 0 | SQL |
| wp_tgnotk_posts | ping_status | 0 | SQL |
| wp_tgnotk_posts | post_password | 0 | SQL |
| wp_tgnotk_posts | post_name | 0 | SQL |
| wp_tgnotk_posts | to_ping | 0 | SQL |
| wp_tgnotk_posts | pinged | 21 | SQL |
| wp_tgnotk_posts | post_content_filtered | 76 | SQL |
| wp_tgnotk_posts | guid | 11662 | SQL |
| wp_tgnotk_posts | post_type | 0 | SQL |
| wp_tgnotk_posts | post_mime_type | 0 | SQL |
| wp_tgnotk_term_taxonomy | taxonomy | 0 | SQL |
| wp_tgnotk_term_taxonomy | description | 0 | SQL |
| wp_tgnotk_termmeta | meta_key | 0 | SQL |
| wp_tgnotk_termmeta | meta_value | 0 | SQL |
| wp_tgnotk_terms | name | 0 | SQL |
| wp_tgnotk_terms | slug | 0 | SQL |
| wp_tgnotk_usermeta | meta_key | 0 | SQL |
| wp_tgnotk_usermeta | meta_value | 1 | PHP |
| wp_tgnotk_users | user_login | 0 | SQL |
| wp_tgnotk_users | user_nicename | 0 | SQL |
| wp_tgnotk_users | user_email | 0 | SQL |
| wp_tgnotk_users | user_url | 1 | SQL |
| wp_tgnotk_users | user_activation_key | 0 | SQL |
| wp_tgnotk_users | display_name | 0 | SQL |
+-------------------------------------+-----------------------+--------------+------+
Success: Made 15924 replacements.
0 Comments