converting dynamic sites to static hosting
Security and speed are the two main factors that made me migrate dynamic sites to static sites.
I used to build some small sites without any framework using PHP to reuse common files (headers, footers, database connections) with some minimalistic administration pages to avoid to do vi over ssh to manage content. Security wasn’t a concern, Internet users where nice and respectful back then (or more probably I was young and naive). A badly done image upload can quickly become a hacker paradise. This little php snippet that sends out thousands of emails or worse runs brute force attacks against some powerful institutions.
I used Joomla or Wordpress on some of my less smaller sites. All this sites where made for personal fun or for small community clubs I was part of, and once time passes the sites doesn’t get updated anymore, but you don’t want to kill it by pride. You keep it in the wild, forgetting Joomla’s security updates and still needing your Apache, libapache2-mod-php and PHP.
Time to archive it!
Archive your old sites
Many ways to skin a cat. Browsers have the ability to download a page and their asset. Good enough for small 3 pages sites. I find httrack more elegant and flexible. There are obviously many other tools to get to the same result, all depends on your taste and needs.
httrack is a mirroring tool, it allows to update local mirror when the source has changed, it allows to continue interrupted mirroring processes. For our archive process we will use it in a very simple way.
httrack http://www.example.com -O ~/mirror/
Your site is now mirrored in
We can now upload our HTML, CSS, JS and Images to our hosting provider and update the domain’s DNS entry to point to the new server. Or you could just replace all the files of your PHP site.
If your files (HTML, JS, CSS) contain references to www.example.com it doesn’t matter, since the site is hosted under the same domain.
Hide your admin and update content when needed
If you still need to do updates to your content from time to time, you can keep your PHP site on a server inside your LAN or behind a firewall to limit access. You can even keep it in a Virtualbox or Docker image and run it when needed.
Using httrack, you update your static mirror with
httrack --update http://source.example.com -O ~/mirror/
Your site is now updated with the latest changes in
~/mirror/source.example.com/, and you can upload the content to your HTTP server.