You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
10 KiB

1 year ago
1 year ago
  1. ---
  2. title: NextCloud
  3. type: docs
  4. prev: docs/selfhosting/
  5. ---
  6. ### Nextcloud on Debian
  7. Nextcloud is a flexible file synchronization and sharing solution.Nextcloud includes Nextcloud server( run on linux) and Nextcloud client.Nextcloud is a Free and Open Source community supported,with all enterprise features.
  8. In this doc lets try to install nextcloud server over Nginx and access it over browser client.
  9. #### Nginx
  10. Nginx is Free and Open Source web server which is now also used as reverse proxy,HTTP cache and load balancer.To setup nextcloud we can choose either nginx or apache as webserver.
  11. Install and enable nginx service on the server
  12. ```bash
  13. $ sudo apt install nginx -y
  14. $ sudo systemctl start nginx
  15. $ sudo systemctl enable nginx
  16. ```
  17. ### Installation Steps
  18. #### Prerequisites for mannual installation.
  19. https://docs.nextcloud.com/server/latest/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
  20. ##### Install php8.0 from deb.sury.org
  21. Installing PHP from a third party repository https://deb.sury.org/ which contains the deb packaged version of the latest php and its modules.
  22. This repository supports both Ubuntu and Debian.
  23. ```bash
  24. if [ "$(whoami)" != "root" ]; then
  25. SUDO=sudo
  26. fi
  27. ${SUDO} apt-get update
  28. ${SUDO} apt-get -y install lsb-release ca-certificates curl
  29. ${SUDO} curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
  30. ${SUDO} sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
  31. ${SUDO} apt-get update
  32. ```
  33. ```bash
  34. $ sudo apt policy php8.0
  35. # check for any latest updated php package
  36. ```
  37. ```bash{filename="Install the packages mentioned"}
  38. sudo apt install php8.0-xmlreader php8.0-curl php8.0-gd php8.0-mbstring php8.0-zip php8.0-fpm
  39. ```
  40. Database connectors (either choose from MySQL/MariaDB and Postgresql)
  41. ```bash{filename="mysql database connector"}
  42. $ sudo apt install mariadb-server php8.0-mysql
  43. ```
  44. Caching
  45. ```bash{filename="php modules required for caching"}
  46. $sudo apt install redis php8.0-redis
  47. ```
  48. https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
  49. ```bash
  50. vim /etc/php/8.0/cli/php.ini
  51. update date.timezone = Asia/Kolkata
  52. ```
  53. ```
  54. cd /var/www
  55. sudo wget https://download.nextcloud.com/server/releases/latest.zip
  56. sudo chown www-data:www-data /var/www/nextcloud -R
  57. ```
  58. ```sql
  59. > create database nextcloud_db;
  60. > create user nextcloud_user@localhost identified by 'deeproot';
  61. > grant all privileges on nextcloud_db.* to nextcloud_user@localhost identified by 'deeproot';
  62. > flush privileges
  63. > exit
  64. ```
  65. #### Nginx Configuration file.
  66. paste the following in ```/etc/nginx/sites-enabled/nextcloud``` and remove any default files present.
  67. and also make a symlink from ```/etc/nginx/sites-enabled/nextcloud``` to ```/etc/nginx/sites-available/nextcloud```
  68. host ```nextcloud.vinay.com```
  69. ```
  70. upstream php-handler {
  71. #server 127.0.0.1:9000;
  72. server unix:/var/run/php/php8.0-fpm.sock;
  73. }
  74. # Set the `immutable` cache control options only for assets with a cache busting `v` argument
  75. map $arg_v $asset_immutable {
  76. "" "";
  77. default "immutable";
  78. }
  79. server {
  80. listen 80;
  81. server_name nextcloud.vinay.com;
  82. # Path to the root of your installation
  83. root /var/www/nextcloud;
  84. # Use Mozilla's guidelines for SSL/TLS settings
  85. # https://mozilla.github.io/server-side-tls/ssl-config-generator/
  86. #ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
  87. #ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
  88. # Prevent nginx HTTP Server Detection
  89. server_tokens off;
  90. # HSTS settings
  91. # WARNING: Only add the preload option once you read about
  92. # the consequences in https://hstspreload.org/. This option
  93. # will add the domain to a hardcoded list that is shipped
  94. # in all major browsers and getting removed from this list
  95. # could take several months.
  96. #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
  97. # set max upload size and increase upload timeout:
  98. client_max_body_size 512M;
  99. client_body_timeout 300s;
  100. fastcgi_buffers 64 4K;
  101. # Enable gzip but do not remove ETag headers
  102. gzip on;
  103. gzip_vary on;
  104. gzip_comp_level 4;
  105. gzip_min_length 256;
  106. gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
  107. gzip_types application/atom+xml text/javascript application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm 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;
  108. # Pagespeed is not supported by Nextcloud, so if your server is built
  109. # with the `ngx_pagespeed` module, uncomment this line to disable it.
  110. #pagespeed off;
  111. # The settings allows you to optimize the HTTP2 bandwitdth.
  112. # See https://blog.cloudflare.com/delivering-http-2-upload-speed-improvements/
  113. # for tunning hints
  114. client_body_buffer_size 512k;
  115. # HTTP response headers borrowed from Nextcloud `.htaccess`
  116. #add_header Referrer-Policy "no-referrer" always;
  117. #add_header X-Content-Type-Options "nosniff" always;
  118. #add_header X-Download-Options "noopen" always;
  119. #add_header X-Frame-Options "SAMEORIGIN" always;
  120. #add_header X-Permitted-Cross-Domain-Policies "none" always;
  121. #add_header X-Robots-Tag "noindex, nofollow" always;
  122. #add_header X-XSS-Protection "1; mode=block" always;
  123. # Remove X-Powered-By, which is an information leak
  124. fastcgi_hide_header X-Powered-By;
  125. # Add .mjs as a file extension for javascript
  126. # Either include it in the default mime.types list
  127. # or include you can include that list explicitly and add the file extension
  128. # only for Nextcloud like below:
  129. include mime.types;
  130. types {
  131. text/javascript js mjs;
  132. }
  133. # Specify how to handle directories -- specifying `/index.php$request_uri`
  134. # here as the fallback means that Nginx always exhibits the desired behaviour
  135. # when a client requests a path that corresponds to a directory that exists
  136. # on the server. In particular, if that directory contains an index.php file,
  137. # that file is correctly served; if it doesn't, then the request is passed to
  138. # the front-end controller. This consistent behaviour means that we don't need
  139. # to specify custom rules for certain paths (e.g. images and other assets,
  140. # `/updater`, `/ocm-provider`, `/ocs-provider`), and thus
  141. # `try_files $uri $uri/ /index.php$request_uri`
  142. # always provides the desired behaviour.
  143. index index.php index.html /index.php$request_uri;
  144. # Rule borrowed from `.htaccess` to handle Microsoft DAV clients
  145. location = / {
  146. if ( $http_user_agent ~ ^DavClnt ) {
  147. return 302 /remote.php/webdav/$is_args$args;
  148. }
  149. }
  150. location = /robots.txt {
  151. allow all;
  152. log_not_found off;
  153. access_log off;
  154. }
  155. # Make a regex exception for `/.well-known` so that clients can still
  156. # access it despite the existence of the regex rule
  157. # `location ~ /(\.|autotest|...)` which would otherwise handle requests
  158. # for `/.well-known`.
  159. location ^~ /.well-known {
  160. # The rules in this block are an adaptation of the rules
  161. # in `.htaccess` that concern `/.well-known`.
  162. location = /.well-known/carddav { return 301 /remote.php/dav/; }
  163. location = /.well-known/caldav { return 301 /remote.php/dav/; }
  164. location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
  165. location /.well-known/pki-validation { try_files $uri $uri/ =404; }
  166. # Let Nextcloud's API for `/.well-known` URIs handle all other
  167. # requests by passing them to the front-end controller.
  168. return 301 /index.php$request_uri;
  169. }
  170. # Rules borrowed from `.htaccess` to hide certain paths from clients
  171. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/) { return 404; }
  172. location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
  173. # Ensure this block, which passes PHP files to the PHP process, is above the blocks
  174. # which handle static assets (as seen below). If this block is not declared first,
  175. # then Nginx will encounter an infinite rewriting loop when it prepends `/index.php`
  176. # to the URI, resulting in a HTTP 500 error response.
  177. location ~ \.php(?:$|/) {
  178. # Required for legacy support
  179. rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
  180. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  181. set $path_info $fastcgi_path_info;
  182. try_files $fastcgi_script_name =404;
  183. include fastcgi_params;
  184. fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
  185. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  186. fastcgi_param PATH_INFO $path_info;
  187. fastcgi_param HTTPS off;
  188. fastcgi_param modHeadersAvailable true; # Avoid sending the security headers twice
  189. fastcgi_param front_controller_active true; # Enable pretty urls
  190. #fastcgi_pass php-handler;
  191. fastcgi_intercept_errors on;
  192. fastcgi_request_buffering off;
  193. fastcgi_max_temp_file_size 0;
  194. }
  195. # Serve static files
  196. location ~ \.(?:css|js|mjs|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
  197. try_files $uri /index.php$request_uri;
  198. add_header Cache-Control "public, max-age=15778463, $asset_immutable";
  199. access_log off; # Optional: Don't log access to assets
  200. location ~ \.wasm$ {
  201. default_type application/wasm;
  202. }
  203. }
  204. location ~ \.woff2?$ {
  205. try_files $uri /index.php$request_uri;
  206. expires 7d; # Cache-Control policy borrowed from `.htaccess`
  207. access_log off; # Optional: Don't log access to assets
  208. }
  209. # Rule borrowed from `.htaccess`
  210. location /remote {
  211. return 301 /remote.php$request_uri;
  212. }
  213. location / {
  214. try_files $uri $uri/ /index.php$request_uri;
  215. }
  216. }
  217. ```
  218. #### OpenLDAP & NextCloud.
  219. install ldap php8.0 from deb sury repo
  220. apt install php8.0-ldap
  221. and then later enable LDAP user and group backend on nextcloud Apps