The second part of a series describing the technology behind Dweb.page

In the last tutorial we showed you how to host our service locally. Now we’re going to cover how you can set up your own IPFS node and be part of Dweb.page. It’s important to mention that you can use an IPFS node for a lot of interesting projects and ideas. So even if you have no interested in Dweb.page this tutorial might still provide some value for you.

The following is based on the great tutorial series by Carson Farmer.

Getting a server

To host an IPFS node online, you’re going to need an Ubuntu web server. Generally, you can choose between a lot of different companies for this. Our recommendation for an IPFS node is to look out for the data transfer pricing model because that will be the most expensive part of running your node. For example, AWS charges $0.09/GB which can be quite expensive, and it doesn’t help to decentralize the web if everyone is using AWS 😉.

We’ll be using the Cloud Server M with Ubuntu 18.04 by IONOS for this tutorial since they charge nothing for the data transfer and with the 100$ credit, you can test everything for free at the beginning. But there might be other even better solutions so feel free to use whatever you prefer!

Connecting to your server

We’re using PuTTY to connect to our server. PuTTY is a Secure Shell (SSH) client, which gives us access to the command line of our web server. You can download it here. Once you installed it, you need to know your DNS Hostname. On IONOS you find it in the cloud panel if you click on your server. Next, open PuTTY and enter your hostname. Make sure the port number is set to 22. You can now save this to open the connection in the future easily.

Enter your host and establish the connection

Now click on open and enter your name plus password. Depending on your service provider you either did create a password during the setup process, or you need to create pem file or create a new password first. If everything is correct you should see something like this:

Install IPFS

For installing IPFS on your server, we need to type quite a lot of Linux commands. We’ll present you the commands first, and the explain them a below. So, if you’re not interested in it, you can copy paste it into your command line.



tar xvfz go-ipfs_v0.4.18_linux-amd64.tar.gz

rm go-ipfs_v0.4.18_linux-amd64.tar.gz

sudo mv go-ipfs/ipfs /usr/local/bin

rm -rf go-ipfs

ipfs init -p server wget https://dist.ipfs.io/go-ipfs/v0.4.18/go-ipfs_v0.4.18_linux-amd64.tar.gz tar xvfz go-ipfs_v0.4.18_linux-amd64.tar.gzrm go-ipfs_v0.4.18_linux-amd64.tar.gzsudo mv go-ipfs/ipfs /usr/local/binrm -rf go-ipfsipfs init -p server

The wget command downloads the latest IPFS version on your machine. Then you unpack it with tar xvfz and remove the downloaded archive with rm. sudo mv then moves it to a different directory, and we remove the unpacked folder with rm.

echo 'export IPFS_PATH=/data/ipfs' >>~/.bash_profile

source ~/.bash_profile

sudo mkdir -p $IPFS_PATH

sudo chown root:root $IPFS_PATH

The above lines of code add our repo path to our bash profile to make the IPFS commands easily available in our command line.

ipfs init -p server

ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080

With ipfs init -p server you change the IPFS settings to the server profile, which are optimized settings for running IPFS on a web server. The second line makes our IPFS gateway public accessible.

sudo bash -c 'cat >/lib/systemd/system/ipfs.service <<EOL

[Unit]

Description=ipfs daemon

[Service]

ExecStart=/usr/local/bin/ipfs daemon --enable-gc --writable

Restart=always

User=root

Group=root

Environment="IPFS_PATH=/data/ipfs"

[Install]

WantedBy=multi-user.target

EOL'

The above code creates a service, which makes sure that IPFS is always running on our server. It also gives people write access to your Gateway, which is necessary for Dweb.page. This means that people can use your IPFS gateway to upload content. Usually, this is turned off by default, but people can always request files from your gateway, which is practically the same as uploading content to your gateway directly so that you can turn it on anyway (even if you’re not interested in using Dweb.page).

sudo systemctl daemon-reload

sudo systemctl enable ipfs.service

sudo systemctl start ipfs

sudo systemctl status ipfs

And finally, these commands setup our service and start IPFS. The sudo systemctl status ipsf command checks the status of your IPFS installation. If everything is working, it should look like this:

Setting up a custom domain

You probably want to have your IPFS server running behind a secure public domain, like https://example.com. The first thing you need to do is to buy a custom domain or use a subdomain and point it to the IP Address of your server. Next, we install Nginx on our server with the following commands:

sudo apt-get update

sudo apt-get install nginx

If everything worked, you should see the image below if you open your domain address:

HTTPS

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:certbot/certbot

sudo apt-get install python-certbot-nginx

sudo certbot --nginx -d pactcare.online

The first commands will install the certbot on your web server and make it easier for you to get Let’s Encrypt certificates (HTTPS) for your website. After the last command, a dialog will start inside your command line, which guides you through the setup process. It’s generally recommended to select option 2, which enables automatic redirect.

If you reload your domain now, you should be connected to it via https instead of HTTP.

Update configurations files

Now we need to change our IPFS setup to make it work with https. Therefore, we can use FileZilla. After you have installed it, you can easily establish a connection to your server by opening the Site Manager (File -> Site Manager). It should look similar to the image below:

Under the general tab, you need to change your connection to SFTP and enter your IP address in the host field. Furthermore, you probably need to switch to “Ask for password” and enter your Username. Now you can connect to your server. The first time you establish a connection you also need to agree that you trust this host.

Next, you navigate to /etc/nginx/sites-available. Here we’re going to replace the default config file by our own version below:

In the above file, you need to replace EXAMPLE.COM with your domain. The config is also set up in a way that people can use your Gateway to upload files up to 1 GB. If you don’t want this, simply remove all appearances of client_max_body_size 1000M. Now let’s finally test everything by opening Dweb.page on your IPFS node, for example by entering your domain name plus “/ipfs/SSFQNEKDAMMAJSTMLRPIHSKZMHQTMYITPPLUWLOPYKS9K9YDGJZKTNQHJVD9YGZFOVZKAZHDIDMFWJGUYFZOTSAS9C/”.

If you want to participate in Dweb.page officially, all that is left to do is to send us an email at info[at]pact[dot]care or join or discord server so we can integrate your side on Dweb.page.

Currently, we share the IOTA donations equally among all participants at the end of every month. In the future, we might set up an advertising or long-term storage payment model to make it more attractive for IPFS nodes to participate.