Transferring WordPress to a local instance for development and testing
Install PHP Composer
https://getcomposer.org/download
Install wp-cli
1 2 | composer global require wp-cli /wp-cli-bundle apt-get install less |
Run search and replace
1 2 3 4 5 6 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | /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