{"id":3727,"date":"2024-01-07T18:54:31","date_gmt":"2024-01-07T23:54:31","guid":{"rendered":"https:\/\/osric.com\/chris\/accidental-developer\/?p=3727"},"modified":"2024-01-31T14:35:24","modified_gmt":"2024-01-31T19:35:24","slug":"converting-a-wordpress-site-to-a-static-site-using-wget","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2024\/01\/converting-a-wordpress-site-to-a-static-site-using-wget\/","title":{"rendered":"Converting a WordPress site to a static site using Wget"},"content":{"rendered":"<p>I recently made a <a href=\"https:\/\/youtu.be\/TuKSuOfSB-g\">YouTube tutorial on converting a WordPress site to a static HTML site<\/a>. This blog post is a companion to the video.<\/p>\n<p>First of all, why convert a WordPress site to a static HTML site? There are a number of reasons, but my primary concern is to reduce update fatigue. WordPress software, along with WordPress themes and plugins, have frequent security updates. Many sites have stable content after an initial editing phase, the need to apply never-ending security updates for a site that doesn&#8217;t change doesn&#8217;t make sense.<\/p>\n<p>The example site I used in the tutorial is <a href=\"http:\/\/www.stress2012.com\">www.stress2012.com<\/a>, a site for an academic conference\/workshop that was held in 2012. It&#8217;s 2024: the site content is not going to change.<\/p>\n<p>To mirror the site, I used <a href=\"https:\/\/www.gnu.org\/software\/wget\/\">Wget<\/a> with the following command:<\/p>\n<p><!--more--><\/p>\n<pre><code>wget -k -r http:\/\/www.stress2012.com<\/code><\/pre>\n<p>That created a www.stress2012.com directory in my current working directory. That directory contained all of the HTML files Wget found on the site, as well as all the non-HTML assets (images, stylesheets, Javascript files, etc.).<\/p>\n<p>The document root for the WordPress site was set up at <code>\/var\/www\/stress2012<\/code>. I copied the site mirror to an adjacent location:<\/p>\n<pre><code>sudo cp -r www.stress2012.com \/var\/www\/www.stress2012.com<\/code><\/pre>\n<p>The permissions were off after copying using sudo privileges, so I updated those:<\/p>\n<pre><code>sudo chown -R chris:www-data \/var\/www\/www.stress2012.com<\/code><\/pre>\n<p>Then I copied the Apache web server config file for the WordPress site, <code>\/etc\/apache2\/sites-available\/stress2012<\/code>, to an adjacent location:<\/p>\n<pre><code>sudo cp \/etc\/apache2\/sites-available\/stress2012 \/etc\/apache2\/sites-available\/stress2012-static<\/code><\/pre>\n<p>The most critical change in that file was to update the document root to <code>\/var\/www\/www.stress2012.com<\/code>.<\/p>\n<p>After that change was made, I disabled the WordPress site, enabled the static site, and reloaded the Apache web server:<\/p>\n<pre><code>sudo a2dissite stress2012.conf\r\nsudo a2ensite stress2012-static.conf\r\nsudo systemctl reload apache2<\/code><\/pre>\n<p>That&#8217;s it! The WordPress site has now been converted to a static site.<\/p>\n<p>The WordPress site included a search form, which relied on PHP and MySQL. The HTML is faithfully reproduced on the static site, but of course it is not functional. I examined the search form and found that the first line of the form contained the presumably unique string &#8220;searchform&#8221; followed by 4 additional lines.<\/p>\n<p>I removed the search form from all the HTML pages on the static site using the following command:<\/p>\n<pre><code>cd \/var\/www\/www.stress2012.com\r\nfind -name *.html -exec sed -i '\/searchform\/,+4d' '{}' \\;<\/code><\/pre>\n<p>That latter command is not something you&#8217;d want to run on a production web site unless you&#8217;re feeling really, <em>really<\/em> confident. In this case, I knew I could revert to the WordPress site if anything went awry.<\/p>\n<p>That&#8217;s one of the great things about this particular method of converting a WordPress site to a static site: it&#8217;s easy to re-enable the WordPress site and disable the static HTML site if needed.<\/p>\n<p>Other reasons you might want to use a static HTML site aside from avoiding update fatigue?<\/p>\n<ul>\n<li>The pages should load faster (no backed PHP processing and MySQL queries)<\/li>\n<li>Reduced web server load<\/li>\n<li>Easily moved to other hosting platforms, such as <a href=\"https:\/\/docs.aws.amazon.com\/AmazonS3\/latest\/userguide\/WebsiteHosting.html\">Hosting a static website with Amazon S3<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Wget can be used to mirror an entire website. In this post, I describe using Wget to create a static HTML mirror of a WordPress site and configuring the Apache web server to point to the static HTML site.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[73,573,359],"class_list":["post-3727","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-apache","tag-wget","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=3727"}],"version-history":[{"count":6,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3727\/revisions"}],"predecessor-version":[{"id":3762,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3727\/revisions\/3762"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=3727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=3727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=3727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}