{"id":685,"date":"2022-02-19T19:32:56","date_gmt":"2022-02-19T14:02:56","guid":{"rendered":"https:\/\/www.lguruprasad.in\/blog\/?p=685"},"modified":"2022-02-19T19:42:23","modified_gmt":"2022-02-19T14:12:23","slug":"how-i-set-up-my-self-hosted-matrix-instance","status":"publish","type":"post","link":"https:\/\/www.lguruprasad.in\/blog\/2022\/02\/19\/how-i-set-up-my-self-hosted-matrix-instance\/","title":{"rendered":"How I set up my self-hosted Matrix instance"},"content":{"rendered":"\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/matrix.org\" data-type=\"URL\" data-id=\"https:\/\/matrix.org\" target=\"_blank\">Matrix<\/a> is a modern, decentralized, federated real-time communication protocol and open standard. It has a thriving ecosystem of servers, clients, and applications. <a rel=\"noreferrer noopener\" href=\"https:\/\/matrix.org\/docs\/projects\/server\/synapse\" data-type=\"URL\" data-id=\"https:\/\/matrix.org\/docs\/projects\/server\/synapse\" target=\"_blank\">Synapse<\/a> is the reference server and <a rel=\"noreferrer noopener\" href=\"https:\/\/matrix.org\/docs\/projects\/client\/element\" data-type=\"URL\" data-id=\"https:\/\/matrix.org\/docs\/projects\/client\/element\" target=\"_blank\">Element<\/a> is the reference client for the web, desktop and mobile platforms. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/www.lguruprasad.in\/blog\/wp-content\/uploads\/2022\/02\/Matrix_logo.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lguruprasad.in\/blog\/wp-content\/uploads\/2022\/02\/Matrix_logo.png\" alt=\"Matrix protocol logo\" class=\"wp-image-690\" width=\"285\" height=\"132\"\/><\/a><\/figure><\/div>\n\n\n\n<p>This is something that I have been interested in using and self-hosting for a few years now. I have had an account on the main matrix.org instance for a while now and wanted to switch to a self-hosted instance.<\/p>\n\n\n\n<p>Since I have been using <a rel=\"noreferrer noopener\" href=\"https:\/\/www.docker.com\/\" data-type=\"URL\" data-id=\"https:\/\/www.docker.com\/\" target=\"_blank\">docker<\/a>, <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.docker.com\/compose\/\" data-type=\"URL\" data-id=\"https:\/\/docs.docker.com\/compose\/\" target=\"_blank\">docker-compose<\/a>, and <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.ansible.com\/ansible\/latest\/index.html\" data-type=\"URL\" data-id=\"https:\/\/docs.ansible.com\/ansible\/latest\/index.html\" target=\"_blank\">Ansible<\/a> to deploy and run a wide range of self-hosted applications for my personal use, the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy\" data-type=\"URL\" data-id=\"https:\/\/github.com\/spantaleev\/matrix-docker-ansible-deploy\" target=\"_blank\">spantaleev\/matrix-docker-ansible-deploy<\/a> was my choice for setting up my instance. I chose to use Synapse over <a rel=\"noreferrer noopener\" href=\"https:\/\/matrix.org\/docs\/projects\/server\/dendrite\" data-type=\"URL\" data-id=\"https:\/\/matrix.org\/docs\/projects\/server\/dendrite\" target=\"_blank\">Dendrite<\/a>, the second-generation server because though it is lightweight, it is not feature-complete. All the other third-party implementations have a lot of catching up to do as well, at the time of writing this post.<\/p>\n\n\n\n<p>I learned a bit of <a rel=\"noreferrer noopener\" href=\"https:\/\/www.terraform.io\/\" data-type=\"URL\" data-id=\"https:\/\/www.terraform.io\/\" target=\"_blank\">Terraform<\/a> in my previous job, but never had a chance to learn it properly or build something from scratch using it. So armed with my little knowledge of Terraform, I created a small Terraform project to automate setting up a new Matrix instance. It provisions the DNS records needed for Matrix on <a rel=\"noreferrer noopener\" href=\"https:\/\/www.namecheap.com\" data-type=\"URL\" data-id=\"https:\/\/www.namecheap.com\" target=\"_blank\">Namecheap<\/a> \u2014 my domain registrar and DNS host, provisions an appropriately sized <a rel=\"noreferrer noopener\" href=\"https:\/\/www.hetzner.com\/cloud\" data-type=\"URL\" data-id=\"https:\/\/www.hetzner.com\/cloud\" target=\"_blank\">Hetzner cloud<\/a> instance with a floating IP address, and runs the deployment playbook in the <code>matrix-docker-ansible-deploy<\/code> repository with the provided Ansible variables file. I used the <a rel=\"noreferrer noopener\" href=\"https:\/\/registry.terraform.io\/providers\/hetznercloud\/hcloud\/latest\/docs\" data-type=\"URL\" data-id=\"https:\/\/registry.terraform.io\/providers\/hetznercloud\/hcloud\/latest\/docs\" target=\"_blank\">hcloud<\/a> and the <a rel=\"noreferrer noopener\" href=\"https:\/\/registry.terraform.io\/providers\/namecheap\/namecheap\/latest\/docs\" data-type=\"URL\" data-id=\"https:\/\/registry.terraform.io\/providers\/namecheap\/namecheap\/latest\/docs\" target=\"_blank\">namecheap<\/a> Terraform providers to do this.<\/p>\n\n\n\n<p>With this, I was able to provision and set up my Matrix instance in under 10 minutes by just running<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ terraform plan -out=matrix-plan\n$ terraform apply \"matrix-plan\"<\/code><\/pre>\n\n\n\n<p>I have released the source code for this project <a rel=\"noreferrer noopener\" href=\"https:\/\/gitlab.com\/guruprasad-infrastructure\/matrix\" data-type=\"URL\" data-id=\"https:\/\/gitlab.com\/guruprasad-infrastructure\/matrix\" target=\"_blank\">here<\/a> on GitLab under the GNU Affero General Public License v3.0 (AGPLv3) or later. Since this project contains the <code>matrix-docker-ansible-deploy<\/code> repository as a git submodule, running <code>git submodule update --init<\/code> should automatically pull in a known good commit of that repository to use for the deployment. The <code>README<\/code> file has the instructions for using the project to set Matrix instances from scratch.<\/p>\n\n\n\n<p>I hope it is useful for those who are looking to set up a new Matrix instance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Matrix is a modern, decentralized, federated real-time communication protocol and open standard. It has a thriving ecosystem of servers, clients, and applications. Synapse is the reference server and Element is the reference client for the web, desktop and mobile platforms. This is something that I have been interested in using and self-hosting for a few [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[12,321,1],"tags":[324,314,325,329,328,322,327,323,326],"class_list":["post-685","post","type-post","status-publish","format-standard","hentry","category-foss","category-self-hosting","category-uncategorized","tag-ansible","tag-docker","tag-docker-compose","tag-gitlab","tag-hetzner","tag-matrix","tag-namecheap","tag-synapse","tag-terraform"],"_links":{"self":[{"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":3,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lguruprasad.in\/blog\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}