How to Install ONLYOFFICE Document Server on CentOS 7

ONLYOFFICE Community Server is a multifunctional office suite with a web-based interface that can be installed on any Linux server. It's an open source office and productivity suite, integrated with a CRM system, document server, project management tools and email aggregator.

The ONLYOFFICE Document Server is an open source online office suite like 'Office Online' offered by Microsoft. It's online office suite for viewing and editing text, spreadsheets, and presentations. The ONLYOFFICE Document Server is fully compatible with Open XML formats like .docx, .xlsx, and .pptx. With Document Server, you can enable collaborative editing for your team in real time.

The ONLYOFFICE Document Server can be installed in two ways. We can install it via Docker or install manually on the Linux server. In this tutorial, we will guide you to install and configure 'ONLYOFFICE Document Server' manually on you Linux CentOS 7 server. We will install Document Server under Postgres database with Nginx as the web server.

Prerequisites

  • OS – Ubuntu CentOS 7 64-bit server with kernel 3.13 or later
  • RAM – 2GB or more – we will use 4GB
  • HDD – at least 2 GB of free space

What we will do

  1. Install Epel Repository and preparing the OS
  2. Install and Configure PostgreSQL
  3. Create Database for the ONLYOFFICE Document Server
  4. Install Nodejs
  5. Install Redis Server
  6. Install and Configure RabbitMQ Server
  7. Install and Configure ONLYOFFICE Document Server
  8. Generate New SSL Letsencrypt Certificates
  9. Enable HTTPS for ONLYOFFICE Document Server
  10. Configure Firewalld
  11. Testing

Step 1 – Install Epel Repository and preparing the OS

In this step, we will install third-party CentOS repository Epel (Extra Packages for Enterprise Linux) repository to the system. Install Epel repository with yum command below.

yum -y install epel-release

And for the ONLYOFFICE Document Server installation, we need to disable SELinux (Security-Enhanced Linux) by editing the configuration file '/etc/sysconfig/selinux'.

Disable SELinux by editing the config file with vim.

vim /etc/sysconfig/selinux

Change the 'selinux' value to 'disabled'.

selinux=disabled

Save and exit, then reboot the server.

If all is complete, please login again to the server and check the SELinux status with 'sestatus' command.

sestatus

Make sure the result is 'disabled'.

Install EPEL Repository on CentOS

Step 2 – Install and Configure PostgreSQL

The Document Server can be installed with MySQL and PostgreSQL database. And in this tutorial, we will use PostgreSQL instead of MySQL. Install PostgreSQL database from the repository with yum command.

yum -y install postgresql.x86_64 postgresql-server.x86_64 postgresql-contrib.x86_64

After the installation is complete, we need to initialize the database for the first time by running postgres setup below.

postgresql-setup initdb

Now start PostgreSQL and enable it to run launch automatically at system boot.

systemctl start postgresql
systemctl enable postgresql

PostgreSQL database will run on the localhost IP address with default port 5432 – check it with the netstat command.

netstat -plntu

Next, we need to edit the Postgres authentication file pg_hba.conf with vim.

vim /var/lib/pgsql/data/pg_hba.conf

Change the authentication method for localhost from 'ident' to 'trust' as below. This is for allowing authentication from the local server.

host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust

Save and exit, then restart the PostgreSQL service.

systemctl restart postgresql

Install PostgreSQL database

PostgreSQL Installation and configuration has been completed.

Step 3 – Create the database for the ONLYOFFICE Document Server

PostgreSQL has been installed to the system, and we will create a new database and a new user for the ONLYOFFICE Document Server installation.

Log in to the 'postgres' user and access the postgres command line tool 'psql'.

su – postgres
psql

Change postgres password with your own password and do not use a default and easy password.

\password postgres
Enter new password:

Next, create a new database named 'onlyoffice' with username 'onlyoffice' and the password is 'onlyoffice123@'.

Create all of it by running postgres queries below.

create database onlyoffice;
create user onlyoffice with password 'onlyoffice123@';
grant all privileges on database onlyoffice to onlyoffice;

A new database and user for the Document Server installation has been created.

Create the database in Postgres

Step 4 – Install Nodejs

ONLYOFFICE Document Server require the Nodejs package v6.9.1+. We will install and use Nodejs v6.10 for this tutorial, and it can be installed from the nodesource.com repository.

Add the Nodejs nodesource repository with curl.

curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash –

Nodesource repository has been added, now install Nodejs with yum command below.

yum install -y nodejs

And if the installation has been completed, check the node version with 'node -v' command.

node -v

Nodejs 6.10 installed to the system for the Document Server installation.

Install node.js

Step 5 – Install Redis Server

Redis is an in-memory database persistent on the disk. Used key-value data store for caching, and it's open source. The Document Server installation is required Redis for memory caching. Install Redis from the repository with the yum command below.

yum -y install redis

After the installation is complete, start it and enable it to run automatically at the boot time.

systemctl start redis
systemctl enable redis

By default, redis will run under the localhost IP address with port 6379. Check the port state status with the netstat command, and make sure the state status is 'LISTEN'.

netstat -plntu

Redis server is installed on the server now.

Install Redis Server

Step 6 – Install and Configure RabbitMQ Server

RabbitMQ is an open source message broker software that implements AMQP (Advanced Message Queuing Protocol). It's written in the Erlang language, can be installed for clustering and failover.

The RabbitMQ is required by the Document Server, and we need to install it to the system with the yum command.

yum -y install  rabbitmq-server

After the installation is complete, configure RabbitMQ server to run only on the localhost by creating a new configuration file 'rabbitmq-env.conf' in the rabbitmq directory.

vim /etc/rabbitmq/rabbitmq-env.conf

Paste configuration below.

export RABBITMQ_NODENAME=rabbit@localhost   export RABBITMQ_NODE_IP_ADDRESS=127.0.0.1   export ERL_EPMD_ADDRESS=127.0.0.1

Save and exit.

Start RabbitMQ Server and enable it to launch automatically everytime at system boot.

systemctl start rabbitmq-server
systemctl enable rabbitmq-server

Verify the RabbitMQ installation and configuration, check it with netstat command and you will see the RabbitMQ server is running under localhost IP address with port 5672.

netstat -plntu

Install RabbitMQ

Next, we need to create a new rabbitmq user for the ONLYOFFICE Document Server configuration. Create a new user onlyoffice with password onlyoffice123 with rabbitmqctl commands below.

rabbitmqctl add_user onlyoffice onlyoffice123
rabbitmqctl set_user_tags onlyoffice administrator
rabbitmqctl set_permissions -p / onlyoffice ".*" ".*" ".*"

Now check the new user and make sure the onlyoffice user is available on the list.

rabbitmqctl list_users

rabbitmqctl list_users

The RabbitMQ Server installation and configuration has been completed. And the new rabbitmq user for the Document Server is created.

Step 7 – Install and Configure ONLYOFFICE Document Server

Before we do the Document Server installation, we are required to install the Microsoft font installer and add new latest Nginx repository.

Install 'Microsoft fonts installer' with the yum command below.

yum -y install https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm

Add new latest Nginx repository to the 'yum.repos.d' directory by creating a new file nginx.repo.

vim /etc/yum.repos.d/nginx.repo

Paste configuration below.

[nginx]   name=nginx repo   baseurl=http://nginx.org/packages/centos/7/$basearch/   gpgcheck=0   enabled=1

Save and exit.

Next, add the ONLYOFFICE Document Server GPG key.

rpm –import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x8320CA65CB2DE8E5"

And add new onlyoffice repository file 'onlyoffice.repo' file.

vim /etc/yum.repos.d/onlyoffice.repo

Paste the ONLYOFFICE Document Server repository below.

[onlyoffice]   name=onlyoffice repo   baseurl=http://download.onlyoffice.com/repo/centos/main/noarch/   gpgcheck=1   enabled=1

Save and exit, then install the Document Server.

yum -y install onlyoffice-documentserver

The command will install the Document Server with Nginx web server and the process control supervisor.

Start nginx and supervisord services, then enable it to start automatically at the boot time.

systemctl start nginx
systemctl start supervisord

systemctl enable nginx
systemctl enable supervisord

Start nginx

The Document Server installed, now configure it by executing the command below.

documentserver-configure.sh

You will be asked about the PostgreSQL database.

  • Host: localhost
  • Database name: onlyoffice
  • User: onlyoffice
  • Password: onlyoffice123@

You will be asked about redis configuration. And in this tutorial, redis is running under the server IP instead of the sock file. Type localhost and press 'Enter'.

And lastly, you will be asked about the RabbitMQ Server Credential for the Document Server.

  • Host: localhost:5672
  • User: onlyoffice
  • Password: onlyoffice123

Configure Document Server

The ONLYOFFICE Document Server installation and configuration has been completed.

Step 8 – Generate New SSL Letsencrypt Certificates

The ONLYOFFICE Document Server will run under the HTTPS Secure connection, and we need to generate new SSL certificate files. For this purpose, We will use free SSL Certificate from Letsencrypt.

Before generating certificate files, we need to stop nginx and firewalld services.

systemctl stop nginx
systemctl stop firewalld

Now install 'certbot' Letsencrypt client created by EFF (Electronic Frontier Foundation) from the repository.

yum -y install certbot

After the installation is complete, generate new certificate files for the Document Server domain name 'onlyoffice.hakase-labs.me' with the certbot command below.

certbot certonly –standalone -d onlyoffic.hakase-labs.me

You will be asked about your email, type your email address 'hakase-labs@gmail.com', then accept Term of Service (TOS) by typing 'A', and for the email sharing, type 'N' for no.

Generate SSL cert with Certbot

Next, type the domain name 'onlyoffice.hakase-labs.me' and wait for certbot generating certificate files for you. If there is no error, you will see the result as below.

Let's Encrypt SSL certificate has been created Successfully

New certificate files are now available in the '/etc/letsencrypt/live/' directory.

Next, create new SSL directory and copy generated certificate files to the SSL directory.

mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl/

Copy 'fullchain.pem' and 'privkey.pem' certificate files to the SSL directory.

cp /etc/letsencrypt/live/onlyoffice.irsyadf.me/fullchain.pem .
cp /etc/letsencrypt/live/onlyoffice.irsyadf.me/privkey.pem .

Next, generate the DHPARAM file to get more secure with OpenSSL command below.

openssl dhparam -out dhparam.pem 2048

After everything is complete, change the permission of all certificate files to 600.

chmod 600 *

Configurae SSL in Nginx

SSL Certificate files and DHPARAM file generated.

Step 9 – Enable HTTPS for ONLYOFFICE Document Server

The virtual host configuration for the Document Server is available under the 'conf.d' directory, and it's automatically created during the installation.

Please go to the nginx 'conf.d' directory.

cd /etc/nginx/conf.d/

Backup non-SSL virtual host configuration and copy new SSL template virtual host for the Document Server 'onlyoffice-documentserver-ssl.conf'.

mv onlyoffice-documentserver.conf onlyoffice-documentserver.conf.backup
cp onlyoffice-documentserver-ssl.conf.template onlyoffice-documentserver-ssl.conf

Edit the virtual host SSL file with vim.

vim onlyoffice-documentserver-ssl.conf

Change the server_name value to your domain line 7.

server_name onlyoffice.irsyadf.me;

Add new configuration below line '29', give the server_name with value as your domain name.

server_name onlyoffice.irsyadf.me;

Change the path of SSL files to your certificate files directory line 37-38, and disable the client side SSL certificate files as below.

ssl_certificate /etc/nginx/ssl/fullchain.pem;   ssl_certificate_key /etc/nginx/ssl/privkey.pem;   #ssl_verify_client {{SSL_VERIFY_CLIENT}};   #ssl_client_certificate {{CA_CERTIFICATES_PATH}};

For the HSTS configuration line 44, give the max-age a new value.

add_header Strict-Transport-Security max-age=31536000;

And for the DHPARAM file, change to your path directory line 68.

ssl_dhparam /etc/nginx/ssl/dhparam.pem;

Save and exit.

Then test the configuration file and make sure there is no error, then restart the nginx service.

nginx -t
systemctl restart nginx

Check Nginx configuration syntax

HTTPS for the ONLYOFFICE Document Server is enabled.

Step 10 – Configure Firewalld

If you do not have the Firewalld on your server, install it with the command below.

yum -y install firewalld

After the installation is complete, start it and add it to run automatically at the boot time.

systemctl start firewalld
systemctl enable firewalld

Next, add new HTTP and HTTPS services to the firewalld configuration with 'firewall-cmd' command.

firewall-cmd –permanent –add-service=http
firewall-cmd –permanent –add-service=https

Configure the Firewall

Reload the firewalld configuration, check all available services, and make sure HTTP and HTTPS are on the lists.

firewall-cmd –reload
firewall-cmd –list-all

List Firewall ports

Firewalld configuration for the Document Server has been completed.

Step 11 – Testing

Open your web browser, visit the Document Server domain name 'onlyoffice.hakase-labs.me' and you will be redirected to the HTTPS Secure connection. And make sure the result is as shown below.

Test ONLYOFFICE installation

We've successful installed ONLYOFFICE Document Server with PostgreSQL as the Database and Nginx as the web server using CentOS 7 system.

Reference