logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

gentoo_en.md (15649B)


  1. # Manual install on Gentoo GNU/Linux
  2. {! backend/installation/otp_vs_from_source.include !}
  3. This guide covers a manual from-source installation. To use the gentoo package, please check the [packaged installation guide for gentoo](./gentoo_otp_en.md).
  4. ## Installation
  5. This guide will assume that you have administrative rights, either as root or a user with [sudo permissions](https://wiki.gentoo.org/wiki/Sudo). Lines that begin with `#` indicate that they should be run as the superuser. Lines using `$` should be run as the indicated user, e.g. `pleroma$` should be run as the `pleroma` user.
  6. {! backend/installation/generic_dependencies.include !}
  7. ### Your make.conf, package.use, and USE flags
  8. The only specific USE flag you should need is the `uuid` flag for `dev-db/postgresql`. Add the following line to any new file in `/etc/portage/package.use`. If you would like a suggested name for the file, either `postgresql` or `pleroma` would do fine, depending on how you like to arrange your package.use flags.
  9. ```text
  10. dev-db/postgresql uuid
  11. ```
  12. You could opt to add `USE="uuid"` to `/etc/portage/make.conf` if you'd rather set this as a global USE flags, but this flags does unrelated things in other packages, so keep that in mind if you elect to do so.
  13. Double check your compiler flags in `/etc/portage/make.conf`. If you require any special compilation flags or would like to set up remote builds, now is the time to do so. Be sure that your CFLAGS and MAKEOPTS make sense for the platform you are using. It is not recommended to use above `-O2` or risky optimization flags for a production server.
  14. ### Installing a cron daemon
  15. Gentoo quite pointedly does not come with a cron daemon installed, and as such it is recommended you install one to automate certbot renewals and to allow other system administration tasks to be run automatically. Gentoo has [a whole wide world of cron options](https://wiki.gentoo.org/wiki/Cron) but if you just want A Cron That Works, `emerge --ask virtual/cron` will install the default cron implementation (probably cronie) which will work just fine. For the purpouses of this guide, we will be doing just that.
  16. ### Required ebuilds
  17. * `dev-db/postgresql`
  18. * `dev-lang/elixir`
  19. * `dev-vcs/git`
  20. * `dev-util/cmake`
  21. * `sys-apps/file`
  22. #### Optional ebuilds used in this guide
  23. * `www-servers/nginx` (preferred, example configs for other reverse proxies can be found in the repo)
  24. * `app-crypt/certbot` (or any other ACME client for Let’s Encrypt certificates)
  25. * `app-crypt/certbot-nginx` (nginx certbot plugin that allows use of the all-powerful `--nginx` flag on certbot)
  26. * `media-gfx/imagemagick`
  27. * `media-video/ffmpeg`
  28. * `media-libs/exiftool`
  29. ### Prepare the system
  30. * First ensure that you have the latest copy of the portage ebuilds if you have not synced them yet:
  31. ```shell
  32. # emaint sync -a
  33. ```
  34. * Emerge all required the required and suggested software in one go:
  35. ```shell
  36. # emerge --ask dev-db/postgresql dev-lang/elixir dev-vcs/git www-servers/nginx app-crypt/certbot app-crypt/certbot-nginx dev-util/cmake sys-apps/file
  37. ```
  38. If you would not like to install the optional packages, remove them from this line.
  39. If you're running this from a low-powered virtual machine, it should work though it will take some time. There were no issues on a VPS with a single core and 1GB of RAM; if you are using an even more limited device and run into issues, you can try creating a swapfile or use a more powerful machine running Gentoo to [cross build](https://wiki.gentoo.org/wiki/Cross_build_environment). If you have a wait ahead of you, now would be a good time to take a break, stretch a bit, refresh your beverage of choice and/or get a snack, and reply to Arch users' posts with "I use Gentoo btw" as we do.
  40. ### Install PostgreSQL
  41. [Gentoo Wiki article](https://wiki.gentoo.org/wiki/PostgreSQL) as well as [PostgreSQL QuickStart](https://wiki.gentoo.org/wiki/PostgreSQL/QuickStart) might be worth a quick glance, as the way Gentoo handles postgres is slightly unusual, with built in capability to have two different databases running for testing and live or whatever other purpouse. While it is still straightforward to install, it does mean that the version numbers used in this guide might change for future updates, so keep an eye out for the output you get from `emerge` to ensure you are using the correct ones.
  42. * Install postgresql if you have not done so already:
  43. ```shell
  44. # emerge --ask dev-db/postgresql
  45. ```
  46. Ensure that `/etc/conf.d/postgresql-11` has the encoding you want (it defaults to UTF8 which is probably what you want) and make any adjustments to the data directory if you find it necessary. Be sure to adjust the number at the end depending on what version of postgres you actually installed.
  47. * Initialize the database cluster
  48. The output from emerging postgresql should give you a command for initializing the postgres database. The default slot should be indicated in this command, ensure that it matches the command below.
  49. ```shell
  50. # emerge --config dev-db/postgresql:11
  51. ```
  52. * Start postgres and enable the system service
  53. ```shell
  54. # /etc/init.d/postgresql-11 start
  55. # rc-update add postgresql-11 default
  56. ```
  57. ### A note on licenses, the AGPL, and deployment procedures
  58. If you do not plan to make any modifications to your Pleroma instance, cloning directly from the main repo will get you what you need. However, if you plan on doing any contributions to upstream development, making changes or modifications to your instance, making custom themes, or want to play around--and let's be honest here, if you're using Gentoo that is most likely you--you will save yourself a lot of headache later if you take the time right now to fork the Pleroma repo and use that in the following section.
  59. Not only does this make it much easier to deploy changes you make, as you can commit and pull from upstream and all that good stuff from the comfort of your local machine then simply `git pull` on your instance server when you're ready to deploy, it also ensures you are compliant with the Affero General Public Licence that Pleroma is licenced under, which stipulates that all network services provided with modified AGPL code must publish their changes on a publicly available internet service and for free. It also makes it much easier to ask for help from and provide help to your fellow Pleroma admins if your public repo always reflects what you are running because it is part of your deployment procedure.
  60. ### Install media / graphics packages (optional, see [`docs/installation/optional/media_graphics_packages.md`](docs/installation/optional/media_graphics_packages.md))
  61. ```shell
  62. # emerge --ask media-video/ffmpeg media-gfx/imagemagick media-libs/exiftool
  63. ```
  64. ### Install PleromaBE
  65. * Add a new system user for the Pleroma service and set up default directories:
  66. Remove `,wheel` if you do not want this user to be able to use `sudo`, however note that being able to `sudo` as the `pleroma` user will make finishing the installation and common maintenance tasks somewhat easier:
  67. ```shell
  68. # useradd -m -G users,wheel -s /bin/bash pleroma
  69. ```
  70. Optional: If you are using sudo, review your sudo setup to ensure it works for you. The `/etc/sudoers` file has a lot of options and examples to help you, and [the Gentoo sudo guide](https://wiki.gentoo.org/wiki/Sudo) has more information. Finishing this installation will be somewhat easier if you have a way to sudo from the `pleroma` user, but it might be best to not allow that user to sudo during normal operation, and as such there will be a reminder at the end of this guide to double check if you would like to lock down the `pleroma` user after initial setup.
  71. **Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don't have or want `sudo` or would like to use the system as the `pleroma` user for instance maintenance tasks, you can simply use `su - pleroma` to switch to the `pleroma` user.
  72. * Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
  73. It is highly recommended you use your own fork for the `https://path/to/repo` part below, however if you foolishly decide to forego using your own fork, the primary repo `https://git.pleroma.social/pleroma/pleroma` will work here.
  74. ```shell
  75. pleroma$ cd ~
  76. pleroma$ git clone -b stable https://path/to/repo
  77. ```
  78. * Change to the new directory:
  79. ```shell
  80. pleroma$ cd ~/pleroma
  81. ```
  82. * Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
  83. ```shell
  84. pleroma$ mix deps.get
  85. ```
  86. * Generate the configuration:
  87. ```shell
  88. pleroma$ MIX_ENV=prod mix pleroma.instance gen
  89. ```
  90. * Answer with `yes` if it asks you to install `rebar3`.
  91. * This part precompiles some parts of Pleroma, so it might take a few moments
  92. * After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
  93. * Spend some time with `generated_config.exs` to ensure that everything is in order. If you plan on using an S3-compatible service to store your local media, that can be done here. You will likely mostly be using `prod.secret.exs` for a production instance, however if you would like to set up a development environment, make a copy to `dev.secret.exs` and adjust settings as needed as well.
  94. ```shell
  95. pleroma$ mv config/generated_config.exs config/prod.secret.exs
  96. ```
  97. * The previous command creates also the file `config/setup_db.psql`, with which you can create the database. Ensure that it is using the correct database name on the `CREATE DATABASE` and the `\c` lines, then run the postgres script:
  98. ```shell
  99. pleroma$ sudo -Hu postgres psql -f config/setup_db.psql
  100. ```
  101. * Now run the database migration:
  102. ```shell
  103. pleroma$ MIX_ENV=prod mix ecto.migrate
  104. ```
  105. * Now you can start Pleroma already
  106. ```shell
  107. pleroma$ MIX_ENV=prod mix phx.server
  108. ```
  109. It probably won't work over the public internet quite yet, however, as we still need to set up a web servere to proxy to the pleroma application, as well as configure SSL.
  110. ### Finalize installation
  111. Assuming you want to open your newly installed federated social network to, well, the federation, you should run nginx or some other webserver/proxy in front of Pleroma. It is also a good idea to set up Pleroma to run as a system service.
  112. #### Nginx
  113. * Install nginx, if not already done:
  114. ```shell
  115. # emerge --ask www-servers/nginx
  116. ```
  117. * Create directories for available and enabled sites:
  118. ```shell
  119. # mkdir -p /etc/nginx/sites-{available,enabled}
  120. ```
  121. * Append the following line at the end of the `http` block in `/etc/nginx/nginx.conf`:
  122. ```Nginx
  123. include sites-enabled/*;
  124. ```
  125. * Setup your SSL cert, using your method of choice or certbot. If using certbot, install it if you haven't already:
  126. ```shell
  127. # emerge --ask app-crypt/certbot app-crypt/certbot-nginx
  128. ```
  129. and then set it up:
  130. ```shell
  131. # mkdir -p /var/lib/letsencrypt/
  132. # certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
  133. ```
  134. If that doesn't work the first time, add `--dry-run` to further attempts to avoid being ratelimited as you identify the issue, and do not remove it until the dry run succeeds. If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again). Often the answer to issues with certbot is to use the `--nginx` flag once you have nginx up and running.
  135. If you are using any additional subdomains, such as for a media proxy, you can re-run the same command with the subdomain in question. When it comes time to renew later, you will not need to run multiple times for each domain, one renew will handle it.
  136. ---
  137. * Copy the example nginx configuration and activate it:
  138. ```shell
  139. # cp /home/pleroma/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/
  140. # ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
  141. ```
  142. * Take some time to ensure that your nginx config is correct
  143. Replace all instances of `example.tld` with your instance's public URL. If for whatever reason you made changes to the port that your pleroma app runs on, be sure that is reflected in your configuration.
  144. Pay special attention to the line that begins with `ssl_ecdh_curve`. It is stongly advised to comment that line out so that OpenSSL will use its full capabilities, and it is also possible you are running OpenSSL 1.0.2 necessitating that you do this.
  145. * (Strongly recommended) serve media on another domain
  146. Refer to the [Hardening your instance](../configuration/hardening.md) document on how to serve media on another domain. We STRONGLY RECOMMEND you to do this to minimize attack vectors.
  147. * Enable and start nginx:
  148. ```shell
  149. # rc-update add nginx default
  150. # /etc/init.d/nginx start
  151. ```
  152. If you are using certbot, it is HIGHLY recommend you set up a cron job that renews your certificate, and that you install the suggested `certbot-nginx` plugin. If you don't do these things, you only have yourself to blame when your instance breaks suddenly because you forgot about it.
  153. First, ensure that the command you will be installing into your crontab works.
  154. ```shell
  155. # /usr/bin/certbot renew --nginx
  156. ```
  157. Assuming not much time has passed since you got certbot working a few steps ago, you should get a message for all domains you installed certificates for saying `Cert not yet due for renewal`.
  158. Now, run crontab as a superuser with `crontab -e` or `sudo crontab -e` as appropriate, and add the following line to your cron:
  159. ```cron
  160. 0 0 1 * * /usr/bin/certbot renew --nginx
  161. ```
  162. This will run certbot on the first of the month at midnight. If you'd rather run more frequently, it's not a bad idea, feel free to go for it.
  163. #### Other webserver/proxies
  164. If you would like to use other webservers or proxies, there are example configurations for some popular alternatives in `/home/pleroma/pleroma/installation/`. You can, of course, check out [the Gentoo wiki](https://wiki.gentoo.org) for more information on installing and configuring said alternatives.
  165. #### Create the uploads folder
  166. Even if you are using S3, Pleroma needs someplace to store media posted on your instance. If you are using the `/home/pleroma/pleroma` root folder suggested by this guide, simply:
  167. ```shell
  168. pleroma$ mkdir -p ~/pleroma/uploads
  169. ```
  170. #### init.d service
  171. * Copy example service file
  172. ```shell
  173. # cp /home/pleroma/pleroma/installation/init.d/pleroma /etc/init.d/
  174. ```
  175. * Be sure to take a look at this service file and make sure that all paths fit your installation
  176. * Enable and start `pleroma`:
  177. ```shell
  178. # rc-update add pleroma default
  179. # /etc/init.d/pleroma start
  180. ```
  181. #### Create your first user
  182. If your instance is up and running, you can create your first user with administrative rights with the following task:
  183. ```shell
  184. pleroma$ MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
  185. ```
  186. #### Privilege cleanup
  187. If you opted to allow sudo for the `pleroma` user but would like to remove the ability for greater security, now might be a good time to edit `/etc/sudoers` and/or change the groups the `pleroma` user belongs to. Be sure to restart the pleroma service afterwards to ensure it picks up on the changes.
  188. #### Further reading
  189. {! backend/installation/further_reading.include !}
  190. ## Questions
  191. Questions about the installation or didn’t it work as it should be, ask in [#pleroma:libera.chat](https://matrix.to/#/#pleroma:libera.chat) via Matrix or **#pleroma** on **libera.chat** via IRC.