Daniil Franks

Daniil Franks

Kazan

IT-Park

Daniil Franks Daniil Franks
+7 (843) 503-16-37 Daniil Franks Daily 11:00 AM — 7:00 PM
RU
Blog

Deploying Your Own Messenger

06/02/2025
Daniil Franks
🎯 Website & Mobile App Development, CRM 💻 Ruby on Rails, React, React Native

🎯 Why You Need Your Own Messenger Based on Nextcloud

A self-hosted messenger on the Nextcloud Talk platform is a solution for teams and organizations that value privacy, independence from third-party services, and the ability to integrate communications with files, calendars, and tasks in a unified space.


🔧 Server Preparation and Basic Environment Setup

Infrastructure Requirements

Initial Access and System Update

Connect to the server via SSH and update packages:

ssh root@99.11.123.94
sudo apt update && sudo apt upgrade -y

Installing LAMP Stack and Dependencies

Nextcloud requires a web server, DBMS, and a set of PHP modules:

sudo apt install apache2 mariadb-server libapache2-mod-php php php-mysql php-gd php-xml php-mbstring php-curl php-zip php-bz2 php-intl php-gmp php-bcmath php-imagick php-redis redis-server unzip wget vim -y

🗄️ MariaDB Database Configuration

Secure Database Initialization

sudo mysql_secure_installation

Follow the prompts: set the root password, remove anonymous users, disable remote root login.

Creating Database and User for Nextcloud

sudo mysql -u root -p

In the MySQL console, execute:

CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'myapp'@'localhost' IDENTIFIED BY 'f4378fh37fh4f29dh8972hd923';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'myapp'@'localhost';
FLUSH PRIVILEGES;
EXIT;
It is recommended to use a strong password and save it in a password manager.

📦 Installing and Configuring Nextcloud

Downloading and Placing Files

cd /var/www/
sudo wget https://download.nextcloud.com/server/releases/latest.zip
sudo unzip latest.zip
sudo mv nextcloud /var/www/nextcloud
sudo chown -R www-data:www-data /var/www/nextcloud
sudo chmod -R 755 /var/www/nextcloud

Apache Virtual Host Configuration

Create the file /etc/apache2/sites-available/nextcloud.conf:

<VirtualHost *:80>
    ServerName test.ru
    DocumentRoot /var/www/nextcloud
    
    <Directory /var/www/nextcloud/>
        Require all granted
        AllowOverride All
        Options FollowSymLinks MultiViews
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/nextcloud_error.log
    CustomLog ${APACHE_LOG_DIR}/nextcloud_access.log combined
</VirtualHost>

Activate the configuration and required modules:

sudo a2ensite nextcloud.conf
sudo a2enmod rewrite headers env dir mime
sudo systemctl restart apache2

Setting Up HTTPS via Let's Encrypt

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d test.ru

Follow the instructions: provide your email, agree to the terms, choose HTTPS redirection.


🌐 Initial Nextcloud Setup via Web Interface

  1. Open https://test.ru in your browser
  2. Create an administrator account
  3. In the "Database Setup" section, specify:
    • Type: MySQL/MariaDB
    • Database name: nextcloud
    • User: myapp
    • Password: f4378fh37fh4f29dh8972hd923
    • Host: localhost
  4. Complete the installation and log in to the control panel

📞 Configuring TURN/STUN Server for Audio and Video Calls

Installing and Configuring Coturn

sudo apt install coturn -y
sudo vim /etc/turnserver.conf

Example configuration:

listening-port=3478
tls-listening-port=5349
listening-ip=99.11.123.94
external-ip=99.11.123.94
relay-ip=99.11.123.94
realm=test.ru
server-name=test.ru
use-auth-secret
static-auth-secret=fdfg5y57j76ge3
user-quota=12
total-quota=1200
stale-nonce=600
cert=/etc/letsencrypt/live/test.ru/fullchain.pem
pkey=/etc/letsencrypt/live/test.ru/privkey.pem
no-loopback-peers
no-multicast-peers

Enable the service:

sudo systemctl enable coturn
sudo systemctl start coturn

Integrating TURN/STUN into Nextcloud Talk

  1. Navigate to Administration → Talk → STUN/TURN servers
  2. Add STUN server: stun:test.ru:3478
  3. Add TURN servers:
    • turn:test.ru:3478 (UDP)
    • turn:test.ru:5349 (TCP)
  4. Specify the static-auth-secret matching your Coturn settings

Forcing TURN Usage (Optional)

In the file /var/www/nextcloud/config/config.php, add:

'turn.force' => true,

Opening Ports in the Firewall

sudo ufw allow 3478/tcp
sudo ufw allow 3478/udp
sudo ufw allow 5349/tcp
sudo ufw allow 5349/udp

🔐 Server Security and Access Management

Creating a Dedicated Administrative User

sudo adduser newuser

Configuring Secure SSH Access

  1. Change the default port in /etc/ssh/sshd_config:
    Port 9070
    PermitRootLogin no
    AllowUsers newuser
    
  2. Open the new port in the firewall:
    sudo ufw allow 9070
    
  3. Restart SSH and verify connection:
    sudo systemctl restart sshd
    ssh -p 9070 newuser@99.11.123.94
    

Granting sudo Privileges (If Needed)

sudo visudo

Add the line:

newuser ALL=(ALL:ALL) ALL

📱 Connecting the Nextcloud Talk Mobile App

Installation and Initial Setup

  1. Install the app from the official store:
  2. Upon launch, specify your server address: https://test.ru
  3. Log in using the account created in the web interface

Granting Permissions

For calls and notifications to work properly, the app requires:

Starting Communication

  1. After logging in, tap "+" in the chat list
  2. Enter the username or email of another system user
  3. Select the communication type: text chat, audio call, or video call

🔍 Diagnostics and Common Issues

Checking Service Status

sudo systemctl status apache2
sudo systemctl status mariadb
sudo systemctl status coturn
sudo tail -f /var/log/apache2/error.log

Testing TURN/STUN Ports

telnet test.ru 3478
telnet test.ru 5349

If calls fail to connect:

If files fail to upload:


Subscribe to my channel and stay updated on all IT news! @daniilfranxx Subscribe

OGRNIP 323169000103441

Daniil Franks Daniil Franks Daniil Franks Daniil Franks Daniil Franks Daniil Franks

* Meta Platforms, Inc., which owns Facebook and Instagram, is banned in Russia.