Deploying your own Hubzilla Hub


Hubzilla

Hubzilla is an awesome decentralized platform that provides users with a nomadic identity within the federation/fediverse.

Hubzilla (and Friendica) are special among the other popular decentralized platforms like Diaspora and Mastadon in that they can connect with and interact with all other platforms.

After trying out hubzilla and getting a taste of these new decentralized social networks, I decided to try and host my own hub. I found a few different guides were helpful but none were very complete.

Here's a walk through of what I did to get my own hub running and to connect that hub to Diaspora, ActivtyPub and GNU Social.

Setting up your VPS


Create a dropelt on Digital Ocean

Create a droplet with the following

  • Ubuntu 18.04
  • 2GB Memory
  • 50 GB Disk

Then ssh into your droplet

ssh root@<droplet_ip>

Create a non-root sudo user

adduser <username> # follow password prompt
usermod -aG sudo <username>

Then ensure you have sudo access

su - username

sudo ls -la /root


Configure DNS

Before installing hubzilla, you need to map your VPS to your domain/subdomain.

If you have an existing domain, example.com and would like to host your hub at hub.example.com

Create the following DNS record

  • Name: hub
  • Type: A
  • Data: <droplet_ip>

Install LAMP Server

This part of the guide was mostly take from https://www.howtoforge.com/tutorial/how-to-install-hubzilla-on-ubuntu/

Install Apache and MariaDB

sudo apt-get install apache2 mariadb-server -y

Get the latest version of php

sudo add-apt-repository --yes ppa:ondrej/php
sudo apt-get update -y
sudo apt-get install php7.2 php7.2-mysql php7.2-curl php7.2-json php7.2-cli php7.2-gd php7.2-xml php7.2-mbstring imagemagick php7.2-zip wget -y

Start Apache and MariaDB service and enable them to start on boot time

sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql

Configure database

Before setting up the database, reset your droplet's root password. This is so you can know what the password is if you originally used an ssh key instead of password ssh authentication.

Go to your droplet's page in the dashboard and click "Access Control", then click "Reset root password"

When you receive the email copy the password and ssh into your droplet again and use it to follow the prompt to set a new password.

Create database and user

<username> refers to the non-root user you created earlier

mysql -u root -p
MariaDB [(none)]> create database hub;
MariaDB [(none)]> grant all privileges on hub.* to <username>@localhost identified by "<user_password>";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

Install Hubzilla

cd /var/www/html
sudo git clone https://framagit.org/hubzilla/core.git hubzilla

Install hubzilla addons\

cd hubzilla
sudo util/add_addon_repo https://framagit.org/hubzilla/addons.git hzaddons

Then set permissions for the web server files

sudo chown -R www-data:www-data /var/www/html/hubzilla/
sudo chmod -R 755 /var/www/html/hubzilla/

Configure Apache

First enable the rewrite module

a2enmod rewrite

Create a new VirtualHost

bash sudo nano /etc/apache2/sites-available/hubzilla.conf

And use this template replacing hub.example.com with your domain

 <VirtualHost *:80>
     ServerAdmin youremail@example.com
     DocumentRoot /var/www/html/hubzilla
     ServerName hub.example.com

     <Directory /var/www/html/hubzilla/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>
     <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/hubzilla_error.log
     CustomLog ${APACHE_LOG_DIR}/hubzilla_access.log combined

Then enable the virtual host and restart apache

sudo a2ensite hubzilla
sudo systemctl restart apache2

Configure SSL

Install the certbot apache plugin

sudo apt-get install python-certbot-apache

Generate a certificate for your hub's domain

When generating the certificate select option 2 to redirect to https

sudo certbot --apache -d hub.example.com

Set up site as admin

Before setting up your hub, I suggest installing sendmail (see Troubleshooing). I had an issue with the default mailer addon, and wasn't able to log in because the confirmation email couldn't send. You may not need to do this, but it fixed my issue.

Now open your hub in your browser at https://hub.example.com

Ensure there are no errors in the checklist and then click "Next"

Fill out the databse connection form

  • Database Server Name: 127.0.0.1
  • Database Port: 0
  • Database Login name: <username> the non-root user you created
  • Database Login Password: the user's password used in the grant privileges statement
  • Database Name: hub
  • Database Type: MySQL

Click "Submit" and fill out the site settings form

Set up polling

Before registering, you will need to setup a schedlued task for the poller

crontab -e

And then add a newline

*/10 * * * *    cd /var/www/html/hubzilla; /usr/bin/php Zotlabs/Daemon/Master.php Cron > /dev/null 2>&1


Federation

To enable your hub to work with the Diaspora, ActivityPub and GNU Social protocols you must enable the addon for your site and then enable the app for your channel

Enabling the addons

1. Log into your hub using your admin credentials
2. Click the dropdown arrow on your profile picture in the top left
3. Select "Admin"
4. Select "Addons" in the left admin menu
5. Enable "Diaspora Statistics", "Diaspora Protocol", "GNU-Social Protocol", "PubCrawl", and "PubSubHubBot"

With these addons enabled, users on your hub should now be able to enable the protocol for their individual channels.

Enabling the apps

  1. Switch to your desired channel
  2. Select dropdown app drawer in the top right
  3. Select "Add apps"
  4. Click "Manage Apps"
  5. Install "Activitypub Protocol", "GNU-Social Protocol", and "Diaspora Protocol"

You can also click on "Diaspora Protocol" and provide a list of hashtags to follow via Diaspora

At this point your channel should be able to federate. However, you may realize that posts and comments aren't reaching your old connections or you're not receving any federated posts in your stream

Checking Federation

You can perform the following checks to test if the protocol is correctly setup.

Connect with your Diaspora or Mastodon acocunt and make a post explicitly shared that with them and tag their name in the message. You should be able to see the post and comment from the other account.

Secondly, you can check https://hub.example.com/.well-known/x-social-relay. If Diaspora is enabled you should see content on this page with "subscribe" set to true. You should also see the list of tags your provided.

You should also see the enabled protocols under the plugins list if you view https://hub.example.com/siteinfo.json

Additionally, you can view https://hub.example.com/well-known/nodeinfo and ensure there are links listed with rel set to nodeinfo.diaspora.software.

Re-connecting with your clone's connections.

After setting up my hub, I cloned and imported my channel from another hub (hub.disroot.org). Although I had all my same connections, they weren't actually connected to my channel at this new location. (You may see this message about lcoation independence when viewing a connection you previously had at a different location/hub.)

To fix this, I simply went through each connection and entered their webbie into the "Add New Connection" field. After adding each connection, their photo should be displayed normally instead of dimmed. You will also see the "Status: Not connected at this location" disappear.

Wait for federation to kick in

I found that even after re-adding my connections and verifying I could communicate with my accounts on Diaspora and Mastodon, the larger volume of posts expected from the federation weren't showing up in my stream. If this occurs just try waiting for a few minutes.

I began manually searching some Diaspora webbies and liking/commenting on the few posts that had been received into my stream. Eventually it seems like the federation process got synced up and I began seeing more posts made from Diaspora and ActivityPub.

Troubleshooing

SSL

If you have trouble with your SSL certificate i.e. you can't access https://hub.example.com, try the following

Ensure rewrite is enabled

a2enmod rewrite

Enable the ssl module

a2enmod ssl

Then edit the .htconfig.php file

root@hub:/var/www/html/hubzilla# nano .htconfig.php

Then findApp::$config['system']['baseurl']

and change 'http://hub.example.com'; to 'https://hub.example.com';

Restart apache

systemctl restart apache2

Ensure the following lines exist at the end of

...
RewriteEngine on
RewriteCond %{SERVER_NAME} =hub.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Confirmation email

If you have issues with sending confirmation emails, try the following

sudo apt-get install sendmail

Then modify /etc/hosts

127.0.0.1   localhost localhost.localdomain
127.0.1.1   hub.example.com hub