Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. # Installation Instructions
  2. ## Choosing your server name
  3. It is important to choose the name for your server before you install Synapse,
  4. because it cannot be changed later.
  5. The server name determines the "domain" part of user-ids for users on your
  6. server: these will all be of the format `@user:my.domain.name`. It also
  7. determines how other matrix servers will reach yours for federation.
  8. For a test configuration, set this to the hostname of your server. For a more
  9. production-ready setup, you will probably want to specify your domain
  10. (`example.com`) rather than a matrix-specific hostname here (in the same way
  11. that your email address is probably `user@example.com` rather than
  12. `user@email.example.com`) - but doing so may require more advanced setup: see
  13. [Setting up Federation](../federate.md).
  14. ## Installing Synapse
  15. ### Prebuilt packages
  16. Prebuilt packages are available for a number of platforms. These are recommended
  17. for most users.
  18. #### Docker images and Ansible playbooks
  19. There is an official synapse image available at
  20. <https://hub.docker.com/r/matrixdotorg/synapse> or at [`ghcr.io/matrix-org/synapse`](https://ghcr.io/matrix-org/synapse)
  21. which can be used with the docker-compose file available at
  22. [contrib/docker](https://github.com/matrix-org/synapse/tree/develop/contrib/docker).
  23. Further information on this including configuration options is available in the README
  24. on hub.docker.com.
  25. Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  26. Dockerfile to automate a synapse server in a single Docker image, at
  27. <https://hub.docker.com/r/avhost/docker-matrix/tags/>
  28. Slavi Pantaleev has created an Ansible playbook,
  29. which installs the official Docker image of Matrix Synapse
  30. along with many other Matrix-related services (Postgres database, Element, coturn,
  31. ma1sd, SSL support, etc.).
  32. For more details, see
  33. <https://github.com/spantaleev/matrix-docker-ansible-deploy>
  34. #### Debian/Ubuntu
  35. ##### Matrix.org packages
  36. Matrix.org provides Debian/Ubuntu packages of Synapse, for the amd64
  37. architecture via <https://packages.matrix.org/debian/>.
  38. To install the latest release:
  39. ```sh
  40. sudo apt install -y lsb-release wget apt-transport-https
  41. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  42. echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" |
  43. sudo tee /etc/apt/sources.list.d/matrix-org.list
  44. sudo apt update
  45. sudo apt install matrix-synapse-py3
  46. ```
  47. Packages are also published for release candidates. To enable the prerelease
  48. channel, add `prerelease` to the `sources.list` line. For example:
  49. ```sh
  50. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  51. echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease" |
  52. sudo tee /etc/apt/sources.list.d/matrix-org.list
  53. sudo apt update
  54. sudo apt install matrix-synapse-py3
  55. ```
  56. The fingerprint of the repository signing key (as shown by `gpg
  57. /usr/share/keyrings/matrix-org-archive-keyring.gpg`) is
  58. `AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058`.
  59. When installing with Debian packages, you might prefer to place files in
  60. `/etc/matrix-synapse/conf.d/` to override your configuration without editing
  61. the main configuration file at `/etc/matrix-synapse/homeserver.yaml`.
  62. By doing that, you won't be asked if you want to replace your configuration
  63. file when you upgrade the Debian package to a later version.
  64. ##### Downstream Debian packages
  65. Andrej Shadura maintains a
  66. [`matrix-synapse`](https://packages.debian.org/sid/matrix-synapse) package in
  67. the Debian repositories.
  68. For `bookworm` and `sid`, it can be installed simply with:
  69. ```sh
  70. sudo apt install matrix-synapse
  71. ```
  72. Synapse is also available in `bullseye-backports`. Please
  73. see the [Debian documentation](https://backports.debian.org/Instructions/)
  74. for information on how to use backports.
  75. `matrix-synapse` is no longer maintained for `buster` and older.
  76. ##### Downstream Ubuntu packages
  77. We do not recommend using the packages in the default Ubuntu repository
  78. at this time, as they are [old and suffer from known security vulnerabilities](
  79. https://bugs.launchpad.net/ubuntu/+source/matrix-synapse/+bug/1848709
  80. ).
  81. The latest version of Synapse can be installed from [our repository](#matrixorg-packages).
  82. #### Fedora
  83. Synapse is in the Fedora repositories as
  84. [`matrix-synapse`](https://src.fedoraproject.org/rpms/matrix-synapse):
  85. ```sh
  86. sudo dnf install matrix-synapse
  87. ```
  88. Additionally, Oleg Girko provides Fedora RPMs at
  89. <https://obs.infoserver.lv/project/monitor/matrix-synapse>
  90. #### OpenSUSE
  91. Synapse is in the OpenSUSE repositories as
  92. [`matrix-synapse`](https://software.opensuse.org/package/matrix-synapse):
  93. ```sh
  94. sudo zypper install matrix-synapse
  95. ```
  96. #### SUSE Linux Enterprise Server
  97. Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  98. <https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/>
  99. #### ArchLinux
  100. The quickest way to get up and running with ArchLinux is probably with the package provided by ArchLinux
  101. <https://archlinux.org/packages/extra/x86_64/matrix-synapse/>, which should pull in most of
  102. the necessary dependencies.
  103. pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):
  104. ```sh
  105. sudo pip install --upgrade pip
  106. ```
  107. If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  108. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  109. compile it under the right architecture. (This should not be needed if
  110. installing under virtualenv):
  111. ```sh
  112. sudo pip uninstall py-bcrypt
  113. sudo pip install py-bcrypt
  114. ```
  115. #### Alpine Linux
  116. 6543 maintains [Synapse packages for Alpine Linux](https://pkgs.alpinelinux.org/packages?name=synapse&branch=edge) in the community repository. Install with:
  117. ```sh
  118. sudo apk add synapse
  119. ```
  120. #### Void Linux
  121. Synapse can be found in the void repositories as
  122. ['synapse'](https://github.com/void-linux/void-packages/tree/master/srcpkgs/synapse):
  123. ```sh
  124. xbps-install -Su
  125. xbps-install -S synapse
  126. ```
  127. #### FreeBSD
  128. Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:
  129. - Ports: `cd /usr/ports/net-im/py-matrix-synapse && make install clean`
  130. - Packages: `pkg install py38-matrix-synapse`
  131. #### OpenBSD
  132. As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  133. underlying the homeserver directory (defaults to `/var/synapse`) has to be
  134. mounted with `wxallowed` (cf. `mount(8)`), so creating a separate filesystem
  135. and mounting it to `/var/synapse` should be taken into consideration.
  136. Installing Synapse:
  137. ```sh
  138. doas pkg_add synapse
  139. ```
  140. #### NixOS
  141. Robin Lambertz has packaged Synapse for NixOS at:
  142. <https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/matrix/synapse.nix>
  143. ### Installing as a Python module from PyPI
  144. It's also possible to install Synapse as a Python module from PyPI.
  145. When following this route please make sure that the [Platform-specific prerequisites](#platform-specific-prerequisites) are already installed.
  146. System requirements:
  147. - POSIX-compliant system (tested on Linux & OS X)
  148. - Python 3.8 or later, up to Python 3.11.
  149. - At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org
  150. If building on an uncommon architecture for which pre-built wheels are
  151. unavailable, you will need to have a recent Rust compiler installed. The easiest
  152. way of installing the latest version is to use [rustup](https://rustup.rs/).
  153. To install the Synapse homeserver run:
  154. ```sh
  155. mkdir -p ~/synapse
  156. virtualenv -p python3 ~/synapse/env
  157. source ~/synapse/env/bin/activate
  158. pip install --upgrade pip
  159. pip install --upgrade setuptools
  160. pip install matrix-synapse
  161. ```
  162. This will download Synapse from [PyPI](https://pypi.org/project/matrix-synapse)
  163. and install it, along with the python libraries it uses, into a virtual environment
  164. under `~/synapse/env`. Feel free to pick a different directory if you
  165. prefer.
  166. This Synapse installation can then be later upgraded by using pip again with the
  167. update flag:
  168. ```sh
  169. source ~/synapse/env/bin/activate
  170. pip install -U matrix-synapse
  171. ```
  172. Before you can start Synapse, you will need to generate a configuration
  173. file. To do this, run (in your virtualenv, as before):
  174. ```sh
  175. cd ~/synapse
  176. python -m synapse.app.homeserver \
  177. --server-name my.domain.name \
  178. --config-path homeserver.yaml \
  179. --generate-config \
  180. --report-stats=[yes|no]
  181. ```
  182. ... substituting an appropriate value for `--server-name` and choosing whether
  183. or not to report usage statistics (hostname, Synapse version, uptime, total
  184. users, etc.) to the developers via the `--report-stats` argument.
  185. This command will generate you a config file that you can then customise, but it will
  186. also generate a set of keys for you. These keys will allow your homeserver to
  187. identify itself to other homeserver, so don't lose or delete them. It would be
  188. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  189. change your homeserver's keys, you may find that other homeserver have the
  190. old key cached. If you update the signing key, you should change the name of the
  191. key in the `<server name>.signing.key` file (the second word) to something
  192. different. See the [spec](https://matrix.org/docs/spec/server_server/latest.html#retrieving-server-keys) for more information on key management).
  193. To actually run your new homeserver, pick a working directory for Synapse to
  194. run (e.g. `~/synapse`), and:
  195. ```sh
  196. cd ~/synapse
  197. source env/bin/activate
  198. synctl start
  199. ```
  200. #### Platform-specific prerequisites
  201. Synapse is written in Python but some of the libraries it uses are written in
  202. C. So before we can install Synapse itself we need a working C compiler and the
  203. header files for Python C extensions.
  204. ##### Debian/Ubuntu/Raspbian
  205. Installing prerequisites on Ubuntu or Debian:
  206. ```sh
  207. sudo apt install build-essential python3-dev libffi-dev \
  208. python3-pip python3-setuptools sqlite3 \
  209. libssl-dev virtualenv libjpeg-dev libxslt1-dev libicu-dev
  210. ```
  211. ##### ArchLinux
  212. Installing prerequisites on ArchLinux:
  213. ```sh
  214. sudo pacman -S base-devel python python-pip \
  215. python-setuptools python-virtualenv sqlite3 icu
  216. ```
  217. ##### CentOS/Fedora
  218. Installing prerequisites on CentOS or Fedora Linux:
  219. ```sh
  220. sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  221. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  222. python3-virtualenv libffi-devel openssl-devel python3-devel \
  223. libicu-devel
  224. sudo dnf groupinstall "Development Tools"
  225. ```
  226. ##### macOS
  227. Installing prerequisites on macOS:
  228. You may need to install the latest Xcode developer tools:
  229. ```sh
  230. xcode-select --install
  231. ```
  232. Some extra dependencies may be needed. You can use Homebrew (https://brew.sh) for them.
  233. You may need to install icu, and make the icu binaries and libraries accessible.
  234. Please follow [the official instructions of PyICU](https://pypi.org/project/PyICU/) to do so.
  235. On ARM-based Macs you may also need to install libjpeg and libpq:
  236. ```sh
  237. brew install jpeg libpq
  238. ```
  239. On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  240. via brew and inform `pip` about it so that `psycopg2` builds:
  241. ```sh
  242. brew install openssl@1.1
  243. export LDFLAGS="-L/usr/local/opt/openssl/lib"
  244. export CPPFLAGS="-I/usr/local/opt/openssl/include"
  245. ```
  246. ##### OpenSUSE
  247. Installing prerequisites on openSUSE:
  248. ```sh
  249. sudo zypper in -t pattern devel_basis
  250. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  251. python-devel libffi-devel libopenssl-devel libjpeg62-devel \
  252. libicu-devel
  253. ```
  254. ##### OpenBSD
  255. A port of Synapse is available under `net/synapse`. The filesystem
  256. underlying the homeserver directory (defaults to `/var/synapse`) has to be
  257. mounted with `wxallowed` (cf. `mount(8)`), so creating a separate filesystem
  258. and mounting it to `/var/synapse` should be taken into consideration.
  259. To be able to build Synapse's dependency on python the `WRKOBJDIR`
  260. (cf. `bsd.port.mk(5)`) for building python, too, needs to be on a filesystem
  261. mounted with `wxallowed` (cf. `mount(8)`).
  262. Creating a `WRKOBJDIR` for building python under `/usr/local` (which on a
  263. default OpenBSD installation is mounted with `wxallowed`):
  264. ```sh
  265. doas mkdir /usr/local/pobj_wxallowed
  266. ```
  267. Assuming `PORTS_PRIVSEP=Yes` (cf. `bsd.port.mk(5)`) and `SUDO=doas` are
  268. configured in `/etc/mk.conf`:
  269. ```sh
  270. doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  271. ```
  272. Setting the `WRKOBJDIR` for building python:
  273. ```sh
  274. echo WRKOBJDIR_lang/python/3.7=/usr/local/pobj_wxallowed \\nWRKOBJDIR_lang/python/2.7=/usr/local/pobj_wxallowed >> /etc/mk.conf
  275. ```
  276. Building Synapse:
  277. ```sh
  278. cd /usr/ports/net/synapse
  279. make install
  280. ```
  281. ##### Windows
  282. Running Synapse natively on Windows is not officially supported.
  283. If you wish to run or develop Synapse on Windows, the Windows Subsystem for
  284. Linux provides a Linux environment which is capable of using the Debian, Fedora,
  285. or source installation methods. More information about WSL can be found at
  286. <https://docs.microsoft.com/en-us/windows/wsl/install> for Windows 10/11 and
  287. <https://docs.microsoft.com/en-us/windows/wsl/install-on-server> for
  288. Windows Server.
  289. ## Setting up Synapse
  290. Once you have installed synapse as above, you will need to configure it.
  291. ### Using PostgreSQL
  292. By default Synapse uses an [SQLite](https://sqlite.org/) database and in doing so trades
  293. performance for convenience. Almost all installations should opt to use [PostgreSQL](https://www.postgresql.org)
  294. instead. Advantages include:
  295. - significant performance improvements due to the superior threading and
  296. caching model, smarter query optimiser
  297. - allowing the DB to be run on separate hardware
  298. For information on how to install and use PostgreSQL in Synapse, please see
  299. [Using Postgres](../postgres.md)
  300. SQLite is only acceptable for testing purposes. SQLite should not be used in
  301. a production server. Synapse will perform poorly when using
  302. SQLite, especially when participating in large rooms.
  303. ### TLS certificates
  304. The default configuration exposes a single HTTP port on the local
  305. interface: `http://localhost:8008`. It is suitable for local testing,
  306. but for any practical use, you will need Synapse's APIs to be served
  307. over HTTPS.
  308. The recommended way to do so is to set up a reverse proxy on port
  309. `8448`. You can find documentation on doing so in
  310. [the reverse proxy documentation](../reverse_proxy.md).
  311. Alternatively, you can configure Synapse to expose an HTTPS port. To do
  312. so, you will need to edit `homeserver.yaml`, as follows:
  313. - First, under the `listeners` option, add the configuration for the
  314. TLS-enabled listener like so:
  315. ```yaml
  316. listeners:
  317. - port: 8448
  318. type: http
  319. tls: true
  320. resources:
  321. - names: [client, federation]
  322. ```
  323. - You will also need to add the options `tls_certificate_path` and
  324. `tls_private_key_path`. to your configuration file. You will need to manage provisioning of
  325. these certificates yourself.
  326. - You can find more information about these options as well as how to configure synapse in the
  327. [configuration manual](../usage/configuration/config_documentation.md).
  328. If you are using your own certificate, be sure to use a `.pem` file that
  329. includes the full certificate chain including any intermediate certificates
  330. (for instance, if using certbot, use `fullchain.pem` as your certificate, not
  331. `cert.pem`).
  332. For a more detailed guide to configuring your server for federation, see
  333. [Federation](../federate.md).
  334. ### Client Well-Known URI
  335. Setting up the client Well-Known URI is optional but if you set it up, it will
  336. allow users to enter their full username (e.g. `@user:<server_name>`) into clients
  337. which support well-known lookup to automatically configure the homeserver and
  338. identity server URLs. This is useful so that users don't have to memorize or think
  339. about the actual homeserver URL you are using.
  340. The URL `https://<server_name>/.well-known/matrix/client` should return JSON in
  341. the following format.
  342. ```json
  343. {
  344. "m.homeserver": {
  345. "base_url": "https://<matrix.example.com>"
  346. }
  347. }
  348. ```
  349. It can optionally contain identity server information as well.
  350. ```json
  351. {
  352. "m.homeserver": {
  353. "base_url": "https://<matrix.example.com>"
  354. },
  355. "m.identity_server": {
  356. "base_url": "https://<identity.example.com>"
  357. }
  358. }
  359. ```
  360. To work in browser based clients, the file must be served with the appropriate
  361. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  362. `Access-Control-Allow-Origin: *` which would allow all browser based clients to
  363. view it.
  364. In nginx this would be something like:
  365. ```nginx
  366. location /.well-known/matrix/client {
  367. return 200 '{"m.homeserver": {"base_url": "https://<matrix.example.com>"}}';
  368. default_type application/json;
  369. add_header Access-Control-Allow-Origin *;
  370. }
  371. ```
  372. You should also ensure the `public_baseurl` option in `homeserver.yaml` is set
  373. correctly. `public_baseurl` should be set to the URL that clients will use to
  374. connect to your server. This is the same URL you put for the `m.homeserver`
  375. `base_url` above.
  376. ```yaml
  377. public_baseurl: "https://<matrix.example.com>"
  378. ```
  379. ### Email
  380. It is desirable for Synapse to have the capability to send email. This allows
  381. Synapse to send password reset emails, send verifications when an email address
  382. is added to a user's account, and send email notifications to users when they
  383. receive new messages.
  384. To configure an SMTP server for Synapse, modify the configuration section
  385. headed `email`, and be sure to have at least the `smtp_host`, `smtp_port`
  386. and `notif_from` fields filled out. You may also need to set `smtp_user`,
  387. `smtp_pass`, and `require_transport_security`.
  388. If email is not configured, password reset, registration and notifications via
  389. email will be disabled.
  390. ### Registering a user
  391. One way to create a new user is to do so from a client like
  392. [Element](https://element.io/). This requires registration to be enabled via
  393. the
  394. [`enable_registration`](../usage/configuration/config_documentation.md#enable_registration)
  395. setting.
  396. Alternatively, you can create new users from the command line. This can be done as follows:
  397. 1. If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  398. installed via a prebuilt package, `register_new_matrix_user` should already be
  399. on the search path):
  400. ```sh
  401. cd ~/synapse
  402. source env/bin/activate
  403. synctl start # if not already running
  404. ```
  405. 2. Run the following command:
  406. ```sh
  407. register_new_matrix_user -c homeserver.yaml
  408. ```
  409. This will prompt you to add details for the new user, and will then connect to
  410. the running Synapse to create the new user. For example:
  411. ```
  412. New user localpart: erikj
  413. Password:
  414. Confirm password:
  415. Make admin [no]:
  416. Success!
  417. ```
  418. This process uses a setting
  419. [`registration_shared_secret`](../usage/configuration/config_documentation.md#registration_shared_secret),
  420. which is shared between Synapse itself and the `register_new_matrix_user`
  421. script. It doesn't matter what it is (a random value is generated by
  422. `--generate-config`), but it should be kept secret, as anyone with knowledge of
  423. it can register users, including admin accounts, on your server even if
  424. `enable_registration` is `false`.
  425. ### Setting up a TURN server
  426. For reliable VoIP calls to be routed via this homeserver, you MUST configure
  427. a TURN server. See [TURN setup](../turn-howto.md) for details.
  428. ### URL previews
  429. Synapse includes support for previewing URLs, which is disabled by default. To
  430. turn it on you must enable the `url_preview_enabled: True` config parameter
  431. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  432. previewing in the `url_preview_ip_range_blacklist` configuration parameter.
  433. This is critical from a security perspective to stop arbitrary Matrix users
  434. spidering 'internal' URLs on your network. At the very least we recommend that
  435. your loopback and RFC1918 IP addresses are blacklisted.
  436. This also requires the optional `lxml` python dependency to be installed. This
  437. in turn requires the `libxml2` library to be available - on Debian/Ubuntu this
  438. means `apt-get install libxml2-dev`, or equivalent for your OS.
  439. ### Troubleshooting Installation
  440. `pip` seems to leak *lots* of memory during installation. For instance, a Linux
  441. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  442. happens, you will have to individually install the dependencies which are
  443. failing, e.g.:
  444. ```sh
  445. pip install twisted
  446. ```
  447. If you have any other problems, feel free to ask in
  448. [#synapse:matrix.org](https://matrix.to/#/#synapse:matrix.org).