{"id":819,"date":"2020-08-18T23:42:40","date_gmt":"2020-08-18T23:42:40","guid":{"rendered":"https:\/\/www.antpace.com\/blog\/?p=819"},"modified":"2025-08-25T17:42:16","modified_gmt":"2025-08-25T17:42:16","slug":"migrate-a-wordpress-site-to-aws","status":"publish","type":"post","link":"https:\/\/www.antpace.com\/blog\/migrate-a-wordpress-site-to-aws\/","title":{"rendered":"Migrate a WordPress Site to AWS"},"content":{"rendered":"<p>In a previous article I discussed <a href=\"https:\/\/www.antpace.com\/blog\/website-on-aws\/\" target=\"_blank\" rel=\"noopener\">launching a website on AWS<\/a>. The project was framed as transferring a static site from another hosting provider. This post will extend that to migrating a dynamic WordPress site with existing content.<\/p>\n<h2>Install WordPress<\/h2>\n<p>After following the steps to launch your website to a new AWS EC2 instance, you&#8217;ll be able to connect via sFTP. I use FileZilla as my client. You&#8217;ll need the hostname (public DNS), username (<em>ec2-user<\/em> in this example), and key file for access. The latest version of WordPress can be downloaded from <a href=\"https:\/\/wordpress.org\/\" target=\"_blank\" rel=\"noopener\">wordpress.org<\/a>. Once connected to the server, I copy those files to the root web directory for my setup:\u00a0<em>\/var\/www\/html<\/em><\/p>\n<p>Make sure the <em>wp-config.php<\/em> file has the correct details (username, password) for your database. You should use the same database name from the previous hosting environment.<\/p>\n<h2>Data backup and import<\/h2>\n<p>It is crucial to be sure we don&#8217;t lose any data. I make a MySql dump of the current database and copy the entire <em>wp-content<\/em> folder to my local machine. I&#8217;m careful to not delete or cancel the old server until I am sure the new one is working identically.<\/p>\n<h3 id=\"phpMyAdmin\">Install phpMyAdmin<\/h3>\n<p>After configuring my EC2 instance, I <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/ec2-lamp-amazon-linux-2.html#install-phpmyadmin-lamp-server\" target=\"_blank\" rel=\"noopener\">install phpMyAdmin<\/a> so that I can easily import the sql file.<\/p>\n<pre>sudo yum install php-mbstring -y\nsudo systemctl restart httpd\nsudo systemctl restart php-fpm\ncd \/var\/www\/html\nwget https:\/\/www.phpmyadmin.net\/downloads\/phpMyAdmin-latest-all-languages.tar.gz\nmkdir phpMyAdmin &amp;&amp; tar -xvzf phpMyAdmin-latest-all-languages.tar.gz -C phpMyAdmin --strip-components 1\nrm phpMyAdmin-latest-all-languages.tar.gz\nsudo systemctl start mariadb\n<\/pre>\n<p>The above Linux commands installs the database management software on the root directory of the new web server. It is accessible from a browser via <em>yourdomainname.com\/phpMyAdmin. <\/em>This tool is used to upload the data to the new environment.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-832\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2020\/08\/phpMyAdmin-import.png\" alt=\"phpMyAdmin import screen\" width=\"1299\" height=\"859\" \/><\/p>\n<p>Create the database and make sure the name matches what&#8217;s in <em>wp-config.php<\/em> from the last step. Now you&#8217;ll be able to upload your\u00a0<em>.sql<\/em> file.<\/p>\n<p>Next, I take the <em>wp-content<\/em> folder that I stored on my computer, and copy it over to the new remote. At this point, the site homepage will load correctly. You might notice other pages won&#8217;t resolve, and will produce a 404 &#8220;not found&#8221; response. That error has to do with certain Apache settings, and can be fixed by tweaking some options.<\/p>\n<h2>Server settings<\/h2>\n<p>With my setup, I encountered the above issue with page permalinks . WordPress relies on the\u00a0<em>.htaccess\u00a0<\/em>file to route pages\/posts with their correct URL slugs. By default, this Apache setup does not allow its settings to be overridden by <em>.htaccess<\/em> directives. To fix this issue, the <em>httpd.conf\u00a0<\/em>file needs to be edited. Mine was located in this directory:\u00a0<em>\/etc\/httpd\/conf<\/em><\/p>\n<p>You&#8217;ll need to find (or create) a section that corresponds to\u00a0the default document root:\u00a0<em>&lt;Directory &#8220;\/var\/www\/html&#8221;&gt;&lt;\/Directory&gt;.\u00a0<\/em>In that block, they&#8217;ll be a\u00a0AllowOverride command that is set to &#8220;None&#8221;. That needs to be changed to &#8220;All&#8221; for our configuration file to work.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-843\" src=\"https:\/\/www.antpace.com\/blog\/wp-content\/uploads\/2020\/08\/httpd-conf.png\" alt=\"apache config settings found in the HTTPD conf file\" width=\"854\" height=\"658\" \/><\/p>\n<h2>Final steps<\/h2>\n<p>After all the data and content has been transferred, do some smoke-testing. Try out as many pages and features as you can to make sure the new site is working as it should. Make sure you keep a back-up of everything some place secure (I use an S3 bucket). Once satisfied, you can switch your domain&#8217;s A records to point at the new box. Since the old and new servers will appear identical, I add a console.log(&#8220;new server&#8221;) to the header file. That allows me tell when the DNS update has finally resolved. Afterwards, I can safely cancel\/decommission the old web hosting package.<\/p>\n<p><a href=\"https:\/\/www.antpace.com\/blog\/secure-a-website-with-ssl-and-https-on-aws\/\">Don&#8217;t forget to make sure SSL is setup!<\/a><\/p>\n<h1>Updates<\/h1>\n<p><a href=\"https:\/\/aws.amazon.com\/cloud-migration\/\" target=\"_blank\" rel=\"noopener\">AWS offers an entire suite of services<\/a> to help businesses migrate. <a href=\"https:\/\/aws.amazon.com\/application-migration-service\/\" target=\"_blank\" rel=\"noopener\">AWS Application Migration Service<\/a> is a great choice to &#8220;simplify and expedite your migration while reducing costs&#8221;.<\/p>\n<h2>Upgrade PHP<\/h2>\n<p>In 2023, I used this blog post to stand-up a WordPress website. I was using a theme called <a href=\"https:\/\/wordpress.com\/theme\/balasana\">Balasana<\/a>. When I would try to set &#8220;Site Icon&#8221; (favicon) from the &#8220;customize&#8221; UI I would receive a message stating that &#8220;<em>there has been an error cropping your image<\/em>&#8220;. After a few Google searches, and also asking ChatGPT, the answer seemed to be that <a href=\"https:\/\/www.php.net\/manual\/en\/book.image.php\" target=\"_blank\" rel=\"noopener\">GD<\/a> (a graphics library) was either not installed or not working properly. I played with that for almost an hour, but with no success. GD was installed, and so was ImageMagick (a back-up graphics library that WordPress falls back on).<\/p>\n<p>The correct answer was that I needed to upgrade PHP. The AWS Linux 2 image comes with PHP 7.2. Upgrading to version 7.4 did the trick. I was able to make that happen, very painlessly, by following a blog post from <a href=\"https:\/\/greggborodaty.com\/about\/\" target=\"_blank\" rel=\"noopener\">Gregg Borodaty<\/a> . The title of his post is &#8220;<a href=\"https:\/\/greggborodaty.com\/amazon-linux-2-upgrading-from-php-7-2-to-php-7-4\/\" target=\"_blank\" rel=\"noopener\">Amazon Linux 2: Upgrading from PHP 7.2 to PHP 7.4<\/a>&#8221; (thanks Gregg).<\/p>\n<h2>Update<\/h2>\n<p>My recommendation, as of 2024, is to use a managed WordPress service. I wrote a post about using AWS Lightsail for that purpose: <a href=\"https:\/\/www.antpace.com\/blog\/website-redesign-with-wordpress-gutenberg-via-aws-lightsail\/\">Website Redesign with WordPress Gutenberg via AWS Lightsail<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous article I discussed launching a website on AWS. The project was framed as transferring a static site from another hosting provider. This post will extend that to migrating a dynamic WordPress site with existing content. Install WordPress After following the steps to launch your website to a new AWS EC2 instance, you&#8217;ll &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.antpace.com\/blog\/migrate-a-wordpress-site-to-aws\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Migrate a WordPress Site to AWS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3201,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[8,12,65,77,79,87,143],"class_list":["post-819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-apache","tag-aws","tag-htaccess","tag-linux","tag-mariadb","tag-mysql","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/comments?post=819"}],"version-history":[{"count":1,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/819\/revisions"}],"predecessor-version":[{"id":3202,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/819\/revisions\/3202"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media\/3201"}],"wp:attachment":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media?parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/categories?post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/tags?post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}