I’ve always been fascinated by the idea of peer-to-peer network protocols, and putting my website on a distributed network was something I’ve been meaning to do for a while. The recent increase in blog posts about IPFS finally pushed me over the tipping point. Hopefully, you can read this article on IPFS here.
I am really happy with this change, and I urge everyone to do the same with their websites. IPFS may or may not be the perfect solution to the decentralized web, but we need to start somewhere. In this article, I will try to give a step-by-step guide for putting static websites on IPFS.
First, a bit about getting your feet wet with IPFS. Every file and directory in IPFS can be referenced by a hash that looks like
QmNiMm9LUX9R4Ezu2NAsraxFSyrbNR6rgGwCDu71Dy4NwQ. If you have it installed on your computer, you can go on the command line to download and view files.
ipfs cat QmWATWQ7fVPP2EFGu71UkfnqhYXDYH566qy47CnJDgvs8u
This command will output ‘Hello World’. I chose this as an example, because I assume hello world is something a lot of people will have on their nodes.
Just as easy as getting files, putting files is also easy. Lets say you have a picture of a cat called
ipfs add kitten.jpg give you a hash and your node will start seeding it. You can just give that hash to people you want to share the file with. You can try it like this.
Putting a website on IPFS
So how do we go from putting up a file there to putting up a whole website? Just like most unix commands, IPFS also accepts the parameter
-r for running the command recursively. Let’s say our website is in the public/ directory. If we run
ipfs add -r public/, it will first add all the files and subdirectories into IPFS, and finally give us a hash that represents the whole folder.
Other people can view your website with that hash. The hash changes if you update your website, but you can solve this issue with IPNS. IPNS basically allows you use a private key to update the contents of your files. As long as you have your private key, you can publish updates to your IPFS website.
If you want to use IPNS (you probably do), you need to run `ipfs name publish