You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
9.6 KiB

2 years ago
2 years ago
2 years ago
  1. Movim Deployment
  2. ===================
  3. This tutorial describes the different steps you need to take to deploy Movim on your webserver.
  4. # Get-Started
  5. Movim requires some dependencies to be setup properly.
  6. * A fully working webserver like Apache, nginx or Caddy
  7. * A PHP process manager like php-fpm will usually be required for Nginx
  8. * Root access by SSH with access to the webserver user (most of the time via the user www-data)
  9. * A SQL server with a schema for Movim.
  10. * PostgreSQL (**_strongly recommended_** some features are only available on this database)
  11. * MariaDB 10.2 or higher with utf8mb4 encoding (necessary for emojis 😃 support) AND `utf8mb4_bin` collation.
  12. * MySQL is __NOT__ supported and will throw errors during the migrations, please use PostgreSQL or MariaDB.
  13. * **PHP 8.2 minimum** with :
  14. * PHP mbstring (package ''**php-mbstring**'')
  15. * PHP ImageMagick and GD for the picture processing (package ''**php-imagick**'' and ''**php-gd**'')
  16. * Your database PHP driver (package ''**php-pgsql**'' or ''**php-mysql**'' depending on the type of database server you want to use).
  17. * And the PHP XML (package ''**php-xml**'')
  18. * Also the PHP Zip (package ''**php-zip**'') to import Emojis
  19. ### Debian/Ubuntu
  20. apt install composer php-fpm php-mbstring php-imagick php-gd php-pgsql php-xml php-zip
  21. # General architecture
  22. It's mandatory to understand the general architecture of the project to a certain extent before trying to deploy it.
  23. When you use Movim, it acts as an intermediary between the user's browser and an XMPP server. All the data that is sent and received by these two parties are managed by the Movim core, some of them are also saved in a database (for cache purposes).
  24. From the browser perspective, all communication with Movim is done using WebSockets (except for the "default" page loading). These sockets are proxied through your web-server to the Movim daemon. On the XMPP side Movim connects using pure TCP connections (like any XMPP client).
  25. So all these streams will be managed by the Movim daemon. This daemon needs to be launched with the same user and rights as the web-server (most of the time using the ``www-data`` user).
  26. # Installation
  27. ## Stable version
  28. ### Releases
  29. You can simply follow the GIT tags or download a stable snapshot of this repository on our [Release page](https://github.com/movim/movim/releases). Then follow the steps from [Dependency installation](https://github.com/movim/movim/wiki/Install-Movim#dependency-installation).
  30. ## Development version (repository)
  31. The development version of Movim only comes with the core of the project. To install the dependencies you need to install Git to download the source codes from different repositories.
  32. ```bash
  33. # Install Git so that Composer
  34. # can clone the dependencies into your project
  35. apt-get install git
  36. ```
  37. ### Downloading
  38. Git is required to properly get the source code from the official repository. We recommend to execute the following commands with the `www-data` user (which is the common user for most of the GNU/Linux web servers).
  39. ```bash
  40. cd /var/www/ # Server directory
  41. mkdir movim
  42. chown www-data:www-data movim
  43. sudo -s -u www-data # We use the web-server user
  44. # We copy the source code from the repository
  45. git clone https://github.com/movim/movim.git
  46. ```
  47. ### Dependency installation
  48. Movim requires several dependencies to work properly. These libraries are managed using [Composer](https://getcomposer.org/).
  49. #### If you already have composer
  50. cd movim
  51. composer install
  52. #### If you have to install manually composer
  53. You can install Composer in the Movim directory using the following command or by using your package manager:
  54. ```bash
  55. curl -sS https://getcomposer.org/installer | php
  56. ```
  57. Now you will be able to install the dependencies.
  58. ```bash
  59. # Finally install your project's dependencies
  60. php composer.phar install
  61. ```
  62. ### Update
  63. You can also update your current Movim instance with the following lines (check anyway if the updates do not include any incompatibilities with your current version).
  64. ```bash
  65. cd /var/www/movim/
  66. git pull # To update the Movim source-code
  67. composer install # To update the libraries
  68. ```
  69. If the update comes with some database changes you can run the new migrations (see below).
  70. # Deployment
  71. This part of the tutorial can be followed for the stable and testing installation. They need to be applied **in the correct order**.
  72. ## 1. Rights check
  73. Movim needs reading permissions on its root folder and recursively to be deployed properly. It will also try to create two folders:
  74. * **log/** for the PHP logs
  75. * **cache/** for the internal cache (templates and other system files)
  76. * **public/cache/** for the public caches (pictures, CSS, Javascript…)
  77. You can create the folders in advance and it will skip this step, or you can let it by giving it writing permissions on its root folder:
  78. ```bash
  79. # Use the root user to do the command
  80. mkdir cache
  81. chown www-data movim && chown www-data movim/public && chown www-data movim/cache && chmod u+rwx movim
  82. ```
  83. You might have to replace the `www-data` user with the `apache` or `caddy` user in the last command regarding your OS or the web-server you have.
  84. ## 2. DotEnv configuration
  85. Movim relies on [DotEnv](https://github.com/vlucas/phpdotenv) for its configuration.
  86. To configure Movim copy the `.env.example` file in a new `.env` one and fill the different settings in it.
  87. ```bash
  88. cp .env.example .env
  89. nano .env
  90. ```
  91. You can also set those settings using directly [environment variables like with Docker](https://docs.docker.com/compose/environment-variables/).
  92. ## 3. Database setup
  93. Once the database is setup in the `.env` file create or update the database structure using [Composer](https://getcomposer.org/).
  94. ```bash
  95. composer movim:migrate
  96. ```
  97. ## 4. Start the daemon
  98. To let the browser communicate with the Movim server, you need to launch the daemon. It also needs to be launched using the web server user.
  99. ```bash
  100. sudo -s -u www-data # If you are on Ubuntu
  101. ```
  102. Then start the daemon using the parameters configured in the `.env` file.
  103. ```bash
  104. cd /var/www/movim
  105. php daemon.php start # Launch the daemon
  106. ```
  107. If everything runs as expected you should see:
  108. Movim daemon launched
  109. Base URL : {public url of your pod}
  110. This daemon will be killed once your console is closed. Consider using `systemd` or `init` scripts to keep the daemon running in the foreground even after your disconnection. There are example startup files, like a `systemd` service file, in the [`etc/` directory](https://github.com/movim/movim/tree/master/etc).
  111. ## 5. Web Server configuration
  112. ### 5.1. Virtualhost
  113. Create a virtualhost on your preferred webserver and point the root to the `public/index.php` file. You can have a look at the [default configuration files that we provide](https://github.com/movim/movim/tree/master/etc) if you need some help about that part.
  114. Movim is developped to work at the root of a domain or subdomain. __Don't try to deploy it as a subdirectory__ or you might face some unexpected issues.
  115. ### 5.2. Daemon Websocket proxy
  116. When you launch the daemon, **it will generate the configuration** to apply to the Virtualhost file to "proxify" the WebSockets and display it in the console.
  117. These configurations are dynamically generated to fit your current setup. Whether you use Apache, Caddy or nginx, both possible configuration will be displayed and will display even after you successfully applied them.
  118. ### 5.3. Picture proxy cache
  119. Movim is automatically proxyfying the external pictures to protect its user IPs and prevent large pictures to be loaded without user consent.
  120. This internal proxy is already asking the browser to cache the pictures for a few hours.
  121. It is however **strongly recommended** to also setup a server side cache to prevent multiple users to request the same resource through Movim.
  122. #### On Apache
  123. You will need Apache mods `cache_disk`, `expires`, and `headers`. You can enable them with the a2enmod command. Example: `a2enmod cache_disk`
  124. Then add this section to your Movim VirtualHost
  125. ```
  126. CacheQuickHandler on
  127. CacheLock on
  128. CacheLockPath /tmp/mod_cache-lock
  129. CacheLockMaxAge 5
  130. CacheIgnoreHeaders Set-Cookie
  131. <Location /picture>
  132. CacheEnable disk
  133. CacheHeader on
  134. CacheDefaultExpire 6000
  135. CacheMaxExpire 3600
  136. CacheIgnoreNoLastMod On
  137. ExpiresActive on
  138. ExpiresDefault A3600
  139. Header set Cache-Control public
  140. Header merge Cache-Control max-age=604800
  141. FileETag All
  142. </Location>
  143. ```
  144. Afterwards, reload Apache.
  145. #### On nginx
  146. To do so you can configure ```fastcgi_cache``` on nginx, [check the related documentation](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache).
  147. Add this to your `nginx.conf` in the `http` section:
  148. http {
  149. fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:100m inactive=60m;
  150. fastcgi_cache_key "$scheme$request_method$host$request_uri";
  151. }
  152. And check the related documentation in our nginx example file [movim.conf](https://github.com/movim/movim/blob/master/etc/nginx/conf.d/movim.conf).
  153. #### On Caddy
  154. For caddy you may want to take a look at xcaddy and compiling the server with the following modules: [cache-handler](https://github.com/caddyserver/cache-handler), [cdp-cache](https://github.com/sillygod/cdp-cache)
  155. ## 6. Admin panel
  156. The admin panel is available directly from the Movim UI once an admin user is logged in.
  157. To set a user admin login at least once (to register it in the database). You can then set him admin using the following command.
  158. php daemon.php setAdmin {jid}
  159. The administrators will be listed on the login page of the instance.
  160. Some of the configuration elements are only applied after the reboot of the daemon.