HOW-TO COMPILE AND INSTALL DOCUMENTSERVER ON FREEBSD By Aurélien Croc (AP²C) ==================================================== COMPILATION: ----------- 1. Install the needed dependencies and set some environment variables: $ su # pkg install bash git-lite png jpeg sudo p7zip gmake qt5-qmake npm-node8 \ openjdk8 subversion # npm install -g grunt-cli # ln -s /usr/local/bin/bash /bin/bash # ln -s /usr/local/bin/python2.7 /usr/bin/python # exit $ export QT_SELECT="qt5" 2. Install nodeJS version 8 **compiled with its --shared configure option**. Ports might be patched until this compilation mode is used by default. $ cd /usr/ports/www/node8 $ patch < /dir/to/node8-shared.patch $ make install clean 3. Get the DocumentServer source code: $ git clone --recursive https://github.com/ONLYOFFICE/DocumentServer.git 4. Patch sources if patches are not already integrated into DocumentServer: $ cd DocumentServer/core $ patch < /dir/to/core.patch $ cd ../sdkjs $ patch < /dir/to/sdkjs.patch $ cd ../web-apps $ patch < /dir/to/web-apps.patch $ cd ../server $ patch < /dir/to/server.patch 5. Prepare the 3rd party modules: $ cd ../core/Common/3dParty $ ./make.sh 6. Compiling the core part $ cd ../.. $ gmake PRODUCT_VERSION="5.4.2" BUILD_NUMBER="1" 7. Compiling the sdkjs part $ cd ../sdkjs $ gmake PRODUCT_VERSION="5.4.2" BUILD_NUMBER="1" 8. Compiling the server part $ cd ../server $ gmake PRODUCT_VERSION="5.4.2" BUILD_NUMBER="1" 9. Install DocumentServer: $ su # gmake PRODUCT_VERSION="5.4.2" BUILD_NUMBER="1" install CONFIGURATION: ------------- 1. install needed packages: $ su # pkg install py27-supervisord rabbitmq redis nginx-lite postgresql96-server 2. Enable services at startup in the /etc/rc.conf file: postgresql_enable="YES" nginx_enable="YES" redis_enable="YES" rabbitmq_enable="YES" supervisord_enable="YES" 3. Configure PostgreSQL server: # /usr/local/etc/rc.d/postgresql initdb # /usr/local/etc/rc.d/postgresql start # sudo -i -u postgres psql -c "CREATE DATABASE onlyoffice;" # sudo -i -u postgres psql -c "CREATE USER onlyoffice WITH password 'onlyoffice';" # sudo -i -u postgres psql -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;" # psql -hlocalhost -Uonlyoffice -d onlyoffice -f /var/www/onlyoffice/documentserver/server/schema/postgresql/createdb.sql 4. Configure rabbitmq by setting a password to the guest account: # /usr/local/etc/rc.d/rabbitmq start # rabbitmqctl change_password guest and change it in /etc/onlyoffice/documentserver/default.json accordingly 5. Start redis server: # /usr/local/etc/rc.d/redis start 6. Setup supervisord in order to execute documentserver services: - create the supervisord directory: # mkdir /usr/local/etc/supervisord - let supervisord.conf load files contained in this directory by adding to /usr/local/etc/supervisord.conf: [include] files = /usr/local/etc/supervisord/*.conf - create /var/jail/test/usr/local/etc/supervisord/docservice.conf: [program:docservice] command=/usr/local/bin/node --max_old_space_size=4096 /var/www/onlyoffice/documentserver/server/DocService/sources/server.js directory=/var/www/onlyoffice/documentserver/server/DocService/sources/ user=onlyoffice environment=NODE_ENV=production-linux,NODE_CONFIG_DIR=/etc/onlyoffice/documentserver,NODE_DISABLE_COLORS=1 stdout_logfile=/var/log/onlyoffice/documentserver/docservice/out.log stdout_logfile_backups=0 stdout_logfile_maxbytes=0 stderr_logfile=/var/log/onlyoffice/documentserver/docservice/err.log stderr_logfile_backups=0 stderr_logfile_maxbytes=0 autostart=true autorestart=true - create /var/jail/test/usr/local/etc/supervisord/fileconverter.conf: [program:converter] command=/usr/local/bin/node --max_old_space_size=4096 /var/www/onlyoffice/documentserver/server/FileConverter/sources/convertermaster.js directory=/var/www/onlyoffice/documentserver/server/FileConverter/sources/ user=onlyoffice environment=NODE_ENV=production-linux,NODE_CONFIG_DIR=/etc/onlyoffice/documentserver,NODE_DISABLE_COLORS=1 stdout_logfile=/var/log/onlyoffice/documentserver/converter/out.log stdout_logfile_backups=0 stdout_logfile_maxbytes=0 stderr_logfile=/var/log/onlyoffice/documentserver/converter/err.log stderr_logfile_backups=0 stderr_logfile_maxbytes=0 autostart=true autorestart=true - create /var/jail/test/usr/local/etc/supervisord/gc.conf: [program:gc] command=/usr/local/bin/node /var/www/onlyoffice/documentserver/server/DocService/sources/gc.js directory=/var/www/onlyoffice/documentserver/server/DocService/sources/ user=onlyoffice environment=NODE_ENV=production-linux,NODE_CONFIG_DIR=/etc/onlyoffice/documentserver,NODE_DISABLE_COLORS=1 stdout_logfile=/var/log/onlyoffice/documentserver/gc/out.log stdout_logfile_backups=0 stdout_logfile_maxbytes=0 stderr_logfile=/var/log/onlyoffice/documentserver/gc/err.log stderr_logfile_backups=0 stderr_logfile_maxbytes=0 autostart=true autorestart=true - create /var/jail/test/usr/local/etc/supervisord/metrics.conf: [program:metrics] command=/usr/local/bin/node /var/www/onlyoffice/documentserver/server/Metrics/node_modules/statsd/stats.js ../../config/config.js directory=/var/www/onlyoffice/documentserver/server/Metrics/node_modules/statsd user=onlyoffice environment=NODE_DISABLE_COLORS=1 stdout_logfile=/var/log/onlyoffice/documentserver/metrics/out.log stdout_logfile_backups=0 stdout_logfile_maxbytes=0 stderr_logfile=/var/log/onlyoffice/documentserver/metrics/err.log stderr_logfile_backups=0 stderr_logfile_maxbytes=0 autostart=true autorestart=true - create /var/jail/test/usr/local/etc/supervisord/spellchecker.conf: [program:spellchecker] command=/usr/local/bin/node /var/www/onlyoffice/documentserver/server/SpellChecker/sources/server.js directory=/var/www/onlyoffice/documentserver/server/SpellChecker/sources/ user=onlyoffice environment=NODE_ENV=production-linux,NODE_CONFIG_DIR=/etc/onlyoffice/documentserver,NODE_DISABLE_COLORS=1 stdout_logfile=/var/log/onlyoffice/documentserver/spellchecker/out.log stdout_logfile_backups=0 stdout_logfile_maxbytes=0 stderr_logfile=/var/log/onlyoffice/documentserver/spellchecker/err.log stderr_logfile_backups=0 stderr_logfile_maxbytes=0 autostart=true autorestart=true - create log directories: # mkdir -p /var/log/onlyoffice/documentserver/{spellchecker,metrics,gc,converter,docservice} # chown onlyoffice:onlyoffice /var/log/onlyoffice/documentserver/{spellchecker,metrics,gc,converter,docservice} - load supervisord: # /usr/local/etc/rc.d/supervisord start 7. Setup nginx: - /usr/local/etc/nginx/nginx.conf orker_processes 1; events { worker_connections 1024; } http { map $http_host $this_host { "" $host; default $http_host; } map $http_x_forwarded_proto $the_scheme { default $http_x_forwarded_proto; "" $scheme; } map $http_x_forwarded_host $the_host { default $http_x_forwarded_host; "" $this_host; } map $http_upgrade $proxy_connection { default upgrade; "" close; } proxy_set_header Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $proxy_connection; proxy_set_header X-Forwarded-Host $the_host; proxy_set_header X-Forwarded-Proto $the_scheme; server { listen 127.0.0.2:80; server_tokens off; rewrite ^\/OfficeWeb(\/apps\/.*)$ /web-apps$1 redirect; location / { proxy_pass http://127.0.0.2:8000; proxy_http_version 1.1; } location /spellchecker/ { proxy_pass http://127.0.0.2:8080/; proxy_http_version 1.1; } } } - create the "sites" sub-directory: # mkdir /usr/local/etc/nginx/sites - edit /usr/local/etc/nginx/sites/onlyoffice-documentserver-common.conf: ## Increase this if you want to upload large attachments client_max_body_size 100m; gzip on; gzip_vary on; gzip_types text/plain text/xml text/css text/csv font/ttf application/xml application/javascript application/x-javascript application/json application/octet-stream application/x-font-ttf application/rtf; access_log off; error_log /var/log/onlyoffice/documentserver/nginx.error.log; - edit /usr/local/etc/nginx/sites/onlyoffice-documentserver-docservice.conf: #welcome page rewrite ^/$ $the_scheme://$the_host/welcome/ redirect; #support old version rewrite ^\/OfficeWeb(\/apps\/.*)$ $the_scheme://$the_host/v5.2.8-24/web-apps$1 redirect; #script caching protection rewrite ^(\/web-apps\/apps\/(?!api\/).*)$ $the_scheme://$the_host/v5.2.8-24/$1 redirect; #disable caching for api.js location ~ ^(\/v[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps\/apps\/api\/documents\/api\.js)$ { expires -1; gzip_static on; alias /var/www/onlyoffice/documentserver//$2; } #suppress logging the unsupported locale error location ~ ^(\/v[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps)(\/.*\.json)$ { expires 365d; error_log /dev/null crit; gzip_static on; alias /var/www/onlyoffice/documentserver/$2$3; } location ~ ^(\/v[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?\/(web-apps|sdkjs|sdkjs-plugins|fonts)(\/.*)$ { expires 365d; gzip_static on; alias /var/www/onlyoffice/documentserver/$2$3; } location ~ ^(\/cache\/files.*)(\/.*) { alias /var/lib/onlyoffice/documentserver/App_Data$1; add_header Content-Disposition $arg_disposition; set $secret_string onlyoffice; secure_link $arg_md5,$arg_expires; secure_link_md5 "$secure_link_expires$uri$secret_string"; if ($secure_link = "") { return 403; } if ($secure_link = "0") { return 410; } } # Allow server info only from 127.0.0.1 location /info { allow 127.0.0.1; deny all; proxy_pass http://docservice; } location / { proxy_pass http://docservice; } location ~ ^(\/v[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?(\/doc\/.*) { proxy_pass http://docservice$2; proxy_http_version 1.1; } location /v5.2.8-24/ { proxy_pass http://docservice/; } - edit /usr/local/etc/nginx/sites/onlyoffice-documentserver-spellchecker.conf: location ~ ^(\/v[\d]+\.[\d]+\.[\d]+[\.|-][\d]+)?(\/spellchecker)(\/.*)$ { proxy_pass http://spellchecker$3; proxy_http_version 1.1; } - load nginx: # /usr/local/etc/rc.d/nginx starto 8. Enjoy.