{"id":332,"date":"2015-02-25T01:48:47","date_gmt":"2015-02-25T09:48:47","guid":{"rendered":"https:\/\/cloudinsidr.com\/content\/?p=332"},"modified":"2018-06-13T09:00:49","modified_gmt":"2018-06-13T17:00:49","slug":"how-to-migrate-wordpress-to-a-new-ec2-instance","status":"publish","type":"post","link":"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/","title":{"rendered":"How to migrate your web services from any hosting provider to AWS"},"content":{"rendered":"<p>Leaving your current web hosting provider for the cloud experience may feel rather scary, but in reality, it is a liberating experience.<\/p>\n<p>Just think of all the freedom you gain to run your web services your way: the ability\u00a0to\u00a0use any\u00a0DNS provider of your choice, any certificate authority (such as, most notably, the disruptive force of Letsencrypt),\u00a0install software to your heart&#8217;s content, scale up and out on demand, in other words, be\u00a0in charge of your own services and infrastructure. Here is a quick tutorial on how to\u00a0make the leap.<\/p>\n<p><!--more--><\/p>\n<p>There are quite a few important\u00a0considerations when migrating a web site.\u00a0Are you switching from a control panel-enabled hosting to a &#8220;raw&#8221; infrastructure-as-a-service offering? (In case of AWS EC2, the answer is yes; in case of AWS Lightsail, both yes and no.) Are you also changing your\u00a0web server software (for example, from Apache to NGINX), changing the SAPI, upgrading the PHP engine to take advantage of improved security and higher\u00a0performance, and\/or possibly the database server in the process as well? Here is a comprehensive tutorial on how to set up your new server on Linux with NGINX, PHP, and MySQL\/MariaDB:\u00a0<em><a href=\"https:\/\/www.cloudinsidr.com\/content\/lemp-how-to-set-up-nginx-with-mariadbmysql-and-php-7-x-on-centos-7-rhelfedora\/\" target=\"_blank\" rel=\"noopener\">High-Stakes, High-Security LEMP Setup: Nginx with MariaDB\/MySQL, and PHP 7.x on CentOS 7 (RHEL\/Fedora) with SELinux<\/a>.<\/em><\/p>\n<p>One of the most important questions is how to minimize the downtime. The answer is: by\u00a0being smart about the DNS switch from the old to the new server.<\/p>\n<h3>Step 1. Make\u00a0a backup followed by an update, then another backup<\/h3>\n<p>Backup your CMS &#8220;as is&#8221; on\u00a0the current host. Once you have a backup,\u00a0update all relevant software on\u00a0both systems, then run a backup again.<\/p>\n<hr \/>\n<h6>Quick Tip: Freeze the File System<\/h6>\n<p>If you are running on xfs,\u00a0btrfs, ext3, or\u00a0ext4 and happen to be paranoid, you probably want to make sure no data is lost in the course of a backup. The solution is to freeze and unfreeze the file system as per <a href=\"https:\/\/docs.oracle.com\/cd\/E37670_01\/E37355\/html\/ol_freun_xfs.html\" target=\"_blank\" rel=\"noopener\">Oracle&#8217;s directions found here<\/a>:<\/p>\n<pre class=\"programlisting\"># <strong class=\"userinput\"><code>xfs_freeze -f \/myxfs<\/code><\/strong> # # ... Take snapshot of file system ... # <strong class=\"userinput\"><code>xfs_freeze -u \/myxfs<\/code><\/strong><\/pre>\n<hr \/>\n<h3>Step 2. Install WordPress on the destination host<\/h3>\n<p>As soon as\u00a0your web server with PHP and MySQL\/MariaDB is up and running, wget WordPress and follow the usual installation instructions. On systems with SELinux, you will need to\u00a0adjust SELinux labels on the file system and allow access to TCP sockets.<\/p>\n<h3>Step 3. Migrate your data: uploads, themes, plug-ins, and\u00a0database(s)<\/h3>\n<p>You could dump the databases and rsync the servers, and many people do just that. However, there is an easier way, try it and it will make your jaw drop: the <a href=\"https:\/\/www.digitalmastersmag.com\/magazine\/wordpress-migration-the-easy-way-with-the-all-in-one-wp-migration-plug-in\/\" target=\"_blank\" rel=\"noopener\">All-In-One WordPress Migration Plug-In<\/a>. It can even make replacements (for example,\u00a0replace the\u00a0old\u00a0host name with a new one) in the database if needed.<\/p>\n<h3>Step 5. Adjust the domain name which WordPress identifies with<\/h3>\n<p>Now this part is tricky. You said you wanted to minimize downtime (and who doesn&#8217;t!), here is how to do it:<\/p>\n<ul>\n<li>make sure that the\u00a0TTL for your domain is as short as possible (depending on your current setup, you may need to wait a couple of hours for the new setting to propagate so that it will be respected when you perform\u00a0the DNS switch; you will reverse this setting afterwards),<\/li>\n<li>set up WordPress with all your\u00a0content on your new server using a temporary host name such as www7.yourdomain.tld by enforcing the name switch the the wp-config file of your site&#8217;s configuration (see below for details),<\/li>\n<li>verify that everything is working on the\u00a0new (temporary) host name,<\/li>\n<li>change the web server configuration on your new server to include your usual\u00a0main (SEO-ranked)\u00a0hostname www.yourdomain.tld so that when you switch the DNS to the new server, it will answer requests\u00a0(up to that point, requests won&#8217;t be routed so\u00a0the server can only respond to the temporary host name),<\/li>\n<li><span style=\"line-height: 1.5;\">remove the lines\u00a0that enforce the temporary\u00a0name in wp-config so that WordPress will continue to identify with its usual, SEO-ranked host name (if you made replacements in the database, you should probably reverse them<\/span><span style=\"line-height: 1.5;\">; the amazing All-In-One WordPress Migration Plug-In can take care of that for you by exporting and re-importing the database on the new server with replacements in place),<\/span><\/li>\n<li>at this point WorPress isn&#8217;t working correctly on the new server\u00a0(links will be redirecting to your old server that is receiving requests on your standard host name) but that doesn&#8217;t matter, you are ready to switch the DNS from the old to the new server.<\/li>\n<\/ul>\n<p>All your users who were signed in must sign\u00a0in again, obviously, but other than that, the downtime should be minimal.<\/p>\n<p>Here is the snippet to enforce a\u00a0host name\u00a0in the wp-config.php file of your\u00a0WordPress installation to define how WordPress identifies itself; should you need it, it&#8217;s very handy:<\/p>\n<pre>define('WP_HOME','https:\/\/www.yourdomain.tld\/somedirectory');\r\ndefine('WP_SITEURL','https:\/\/www.yourdomain.tld\/somedirectory<a class=\"external free\" href=\"http:\/\/example.com%27\/\">'<\/a>);<\/pre>\n<p>If\u00a0hard-coding the &#8220;installation identifier&#8221; is not appealing to you, you could enforce an update of the host name by putting a directive into your theme&#8217;s functions.php file, reloading the site a couple of times, and removing these once the change has taken place (check the <a href=\"https:\/\/codex.wordpress.org\/Changing_The_Site_URL\" target=\"_blank\" rel=\"noopener\">Codex<\/a> for more details):<\/p>\n<pre>update_option( 'siteurl', 'https:\/\/www.yourdomain.tld\/somedirectory' );\r\nupdate_option( 'home', 'https:\/\/www.yourdomain.tld\/somedirectory' );<\/pre>\n<p>Just remember to remove the two lines from your functions.php when they are no longer needed (which is, as soon as the update takes place).<\/p>\n<h3>Step 6. Reconfigure DNS<\/h3>\n<p>Now is the time to point\u00a0the DNS configuration away from the old instance to the new server instance. Verify that the site is running (should it\u00a0need some major troubleshooting, reverse the last DNS change to temporarily revert to the old server).\u00a0When you are done, shut down the old server\u00a0so it will not be serving requests.<\/p>\n<p>You may want to increase the TTL in the\u00a0DNS configuration for your domain to reduce unnecessary expenses (you won&#8217;t be migrating anything anytime soon, so your setup\u00a0won&#8217;t be changing).<\/p>\n<h3>Step 7. Celebrate<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Leaving your current web hosting provider for the cloud experience may feel rather scary, but in reality, it is a liberating experience. Just think of all the freedom you gain to run your web services your way: the ability\u00a0to\u00a0use any\u00a0DNS provider of your choice, any certificate authority (such as, most notably, the disruptive force of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":76,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[17,109,6],"tags":[58,63,28,7,84],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to migrate your web services from any hosting provider to AWS - CloudInsidr<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to migrate your web services from any hosting provider to AWS - CloudInsidr\" \/>\n<meta property=\"og:description\" content=\"Leaving your current web hosting provider for the cloud experience may feel rather scary, but in reality, it is a liberating experience. Just think of all the freedom you gain to run your web services your way: the ability\u00a0to\u00a0use any\u00a0DNS provider of your choice, any certificate authority (such as, most notably, the disruptive force of [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudInsidr\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-25T09:48:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-13T17:00:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2015\/11\/cloudinsidr_logo_900px-wide.png\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"326\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/\",\"name\":\"CloudInsidr\",\"description\":\"Cyber security, infotech\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.cloudinsidr.com\/content\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2015\/11\/cloudinsidr_logo_900px-wide.png\",\"width\":900,\"height\":326,\"caption\":\"cloudinsidr.com logo (900px wide)\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/#webpage\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/\",\"name\":\"How to migrate your web services from any hosting provider to AWS - CloudInsidr\",\"isPartOf\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/#primaryimage\"},\"datePublished\":\"2015-02-25T09:48:47+00:00\",\"dateModified\":\"2018-06-13T17:00:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cloudinsidr.com\/content\/how-to-migrate-wordpress-to-a-new-ec2-instance\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\",\"name\":\"Cloud Insidr\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8b2fa1415b3d573b97d818b8f8f83b7c?s=96&d=mm&r=g\",\"caption\":\"Cloud Insidr\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/332"}],"collection":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/comments?post=332"}],"version-history":[{"count":24,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":2251,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/332\/revisions\/2251"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media\/76"}],"wp:attachment":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media?parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/categories?post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/tags?post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}