Contents

Nextcloud on Debian 10

Install

Requirements

Install the requirements:

1
apt install php-fpm php-curl php-xml php-gd php-json php-xml php-mbstring php-zip php-mysql php-bz2 php-intl php-imagick php-gmp php-bcmath ffmpeg nginx certbot python3-certbot-nginx mariadb-server unzip -y 

MariaDB

Initialize MariaDB:

1
mysql_secure_installation

Create the database:

1
2
3
4
5
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
exit;

Nginx

Example config:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
server {
	listen 443 ssl http2;
	listen [::]:443 ssl http2;

	server_name cloud.example.com;

	ssl_certificate /etc/letsencrypt/live/cloud.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloud.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/cloud.example.com/fullchain.pem;

	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=63072000; includeSubdomains" always;

	# 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/cloud.example.com;

	# The following 2 rules are only needed for the user_webfinger app.
	# Uncomment it if you're planning to use this app.
	#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
	#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

	# The following rule is only needed for the Social app.
	# Uncomment it if you're planning to use this app.
	#rewrite ^/.well-known/webfinger /public.php?service=webfinger last;

	location = /.well-known/carddav {
		return 301 $scheme://$host:$server_port/remote.php/dav;
	}

	location = /.well-known/caldav {
		return 301 $scheme://$host:$server_port/remote.php/dav;
	}

	# set max upload size
	client_max_body_size 1024M;
	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-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

	location / {
		rewrite ^ /index.php;
	}

	location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
		deny all;
	}

	location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
		deny all;
	}

	location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy)\.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;
		# Avoid sending the security headers twice
		fastcgi_param modHeadersAvailable true;
		# Enable pretty urls
		fastcgi_param front_controller_active true;
		fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
		fastcgi_intercept_errors on;
		fastcgi_request_buffering off;
	}

	location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
		try_files $uri/ =404;
		index index.php;
	}

	# Adding the cache control header for js, css and map files
	# Make sure it is BELOW the PHP block
	location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
		try_files $uri /index.php$request_uri;
		add_header Cache-Control "public, max-age=15778463";
		add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always;
		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;
	}

	location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
		try_files $uri /index.php$request_uri;
	}
}

server {
	listen 80;
	listen [::]:80;

	server_name cloud.example.com;
	
	return 301 https://$host$request_uri;
}

Certbot

Get a cert from Let’s Encrypt:

1
certbot certonly --nginx -d cloud.example.com --rsa-key-size 4096

Enable config

1
ln -s /etc/nginx/sites-available/cloud.example.com /etc/nginx/sites-enabled/

PHP-FPM

Edit php.ini:

1
nano /etc/php/7.3/fpm/php.ini
1
2
3
4
memory_limit = 1024M
upload_max_filesize = 1024M
post_max_size = 1024M
max_execution_time = 360

Edit www.conf:

1
nano nano /etc/php/7.3/fpm/pool.d/www.conf
1
2
3
4
5
6
# Uncomment and modify the lines
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

Nextcloud

Create the webroot:

1
mkdir /var/www/cloud.example.com

Download Nextcloud from here.

1
2
cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-19.0.1.zip
Security note
Dont forget to check the files integrity!

Extract the files to the webroot:

1
2
unzip nextcloud-19.0.1.zip
mv nextcloud/* /var/www/cloud.example.com

Change files ownership:

1
chown -R www-data:www-data /var/www/cloud.example.com

Installation wizard

Visit the url and complete the installation wizard.