NextCloud on Ubuntu 20.04 with OnlyOffice Integration
Probably also works fine on 18.04 exactly the same- may end up fighting some PHP packages, not sure.
What you’ll need:
NGINX, mariadb, and docker for onlyoffice. Plus an archive from NextCloud and the required PHP packages.. I’ll list the current ones when we get there. Might also need unzip.
You should have a separate NGINX reverse proxy to handle front end traffic– See my post on NGINX reverse proxy, the given configuration will work here if you use https.
Install NGINX, mariadb-server and docker.io:
apt install nginx mariadb-server docker.io
Install the required PHP packages, these are listed on the NextCloud website here: Installation guide
Currently these are what’s listed:
apt install php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip
Now the stuff is there… So let’s setup a database and user for NextCloud:
mysql -u root -p
enter/make a password –
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER ‘username’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON nextcloud.* TO ‘username’@’localhost’;
FLUSH PRIVILEGES;
exit;
Install NextCloud:
Grab an archive of NextCloud from their site with wget:
wget https://download.nextcloud.com/server/releases/nextcloud-22.0.0.zip
Unzip it to /var/www/ #it will create /var/www/nextcloud
unzip nextcloud-22.0.0.zip -d /var/www/
Make sure to set permissions accordingly — chown -R www-data:www-data /var/www/nextcloud
Use occ to install/configure your base nextcloud instance – you always need to run occ as www-data!
sudo -u www-data php occ maintenance:install –database mysql –database-name nextcloud –database-host localhost –database-port 3306 –database-user username –database-pass password –admin-user admuser –admin-pass temp!101 –admin-email your@email.com –data-dir /var/www/nextcloud/data/
Note, for some reason, this admin account won’t work for me – but resetting the password with occ fixes it:
sudo -u www-data php occ user:resetpassword admuser
Now, edit ../nextcloud/config/config.php
trusted domains: include the url you plan to set, usually the LAN IP as well:
‘trusted_domains’ =>
array (
0 => ‘nc.somejoe.com’,
1 => ‘192.168.10.210’,
),
That’s all you need to do here- but add this to get rid of the nextcloud.com link to create your own account on the sign on page: ‘simpleSignUpLink.shown’ => false,
OnlyOffice Document Server on Docker
Let’s get OnlyOffice out of the way with this nifty one-liner.. However, you do need to create a directory for SSL files-
sudo docker run -i -t -d –restart always -p 8088:80 -p 8089:443 -e JWT_ENABLED=true -e JWT_SECRET=yoursecret -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data onlyoffice/documentserver
Put your crt and key in like this:
/app/onlyoffice/DocumentServer/data/certs/onlyoffice.key
/app/onlyoffice/DocumentServer/data/certs/onlyoffice.crt
“yoursecret” is the secret when connection NextCloud to OnlyOffice — I wouldn’t just leave it open –
Configure NGINX:
See NextCloud’s docs on it here: https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
The NGINX config is kind of large, I’ll paste mine here, but you should read the docs on this part.. I bolded my few changes – to fix the strict transport error, and to disallow all bots –
upstream php-handler {
#server 127.0.0.1:9000;
server unix:/var/run/php/php7.4-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name nc.somejoe.com;
# Enforce HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name nc.somejoe.com;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
ssl_certificate /path/to/fullchain.crt;
ssl_certificate_key /path/to/private.key;
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x>
# HTTP response headers borrowed from Nextcloud `.htaccess`
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Strict-Transport-Security max-age=15552000;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /var/www/nextcloud;
# Specify how to handle directories -- specifying `/index.php$request_uri`
# here as the fallback means that Nginx always exhibits the desired behaviour
# when a client requests a path that corresponds to a directory that exists
# on the server. In particular, if that directory contains an index.php file,
# that file is correctly served; if it doesn't, then the request is passed to
# the front-end controller. This consistent behaviour means that we don't need
# to specify custom rules for certain paths (e.g. images and other assets,
# `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
# `try_files $uri $uri/ /index.php$request_uri`
# always provides the desired behaviour.
index index.php index.html /index.php$request_uri;
# Rule borrowed from `.htaccess` to handle Microsoft DAV clients
location = / {
if ( $http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/$is_args$args;
}
}
location = /robots.txt {
add_header Content-Type text/plain;
return 200 "User-agent: *\nDisallow: /\n";
}
# Make a regex exception for `/.well-known` so that clients can still
# access it despite the existence of the regex rule
# `location ~ /(\.|autotest|...)` which would otherwise handle requests
# for `/.well-known`.
location ^~ /.well-known {
# The rules in this block are an adaptation of the rules
# in `.htaccess` that concern `/.well-known`.
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
# Let Nextcloud's API for `/.well-known` URIs handle all other
# requests by passing them to the front-end controller.
return 301 /index.php$request_uri;
}
# Rules borrowed from `.htaccess` to hide certain paths from clients
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
# Ensure this block, which passes PHP files to the PHP process, is above the blocks
# which handle static assets (as seen below). If this block is not declared first,
# then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
# to the URI, resulting in a HTTP 500 error response.
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
fastcgi_param front_controller_active true; # Enable pretty urls
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ \.(?:css|js|svg|gif|png|jpg|ico)$ {
try_files $uri /index.php$request_uri;
expires 6M; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
location ~ \.woff2?$ {
try_files $uri /index.php$request_uri;
expires 7d; # Cache-Control policy borrowed from `.htaccess`
access_log off; # Optional: Don't log access to assets
}
# Rule borrowed from `.htaccess`
location /remote {
return 301 /remote.php$request_uri;
}
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}
My NGINX config will fix the strict transport security warning. You can install php-imagick all you want but it won’t fix the error. To configure opcache to get rid of the “no caching error,” edit /etc/php/7.4/fpm/php.ini and match the following settings:
opcache.enable=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1
Joe
September 29, 2021 at 4:29 pmNote: WordPress murdered my formatting. The mariadb commands use ‘ not ` in real life.. also the occ install command should have double hyphens. I’ll try to update later
joe
November 2, 2021 at 11:43 pmReplies to own comment – I’ll upload config files to make it easier.