# nextCloud-windows安装

# 实践步骤

  1. 下载nextcloud-server源码,并将next-server的3rdParty源码复制进去;
  2. 配置nginx的fastcgi转发;
  3. 启动php-fpm,启动前要开启php.ini的相关插件支持;
extension_dir = "d:\php\ext"
extension=curl
extension=gd2
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
  1. 访问并初始化安装;

# 遇到的坑

  1. 初始化数据库脚本,windows平台无法初始化。由命令中的正则引起;(路径分隔符导致的)
  2. 初始化完成后,php程序阻塞,假死。 暂未发现原因,发现官方明确说明不支持windows,遂放弃,转战centos;

# 参考文档

  • nextcloud不支持windows-https://blog.csdn.net/u011423258/article/details/113559280 ;
  • windows 本地运行php项目-https://blog.csdn.net/weixin_45842139/article/details/130917364;

# nextCloud-linux安装(centos7)

# 安装php7.4

yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum-config-manager --enable remi-php74

yum install -y php php-cli php-fpm php-common php-devel php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-intl php-pecl-apcu php-opcache
  • 不要用源码编译的方式,缺少依赖,有坑费时间;

# 下载nextCloud

  • 下载nextCloud-server的源码
  • 下载nextCloud的sumodule中的源码,并拷贝至3rdParty目录下;
  • 授权: chown -R apache:apache nextcloud-server; 注意,这个apache是php安装时默认的用户名和用户组;

# 启动fpm

  • systemctl start php-fpm

# 配置ng

server {
        listen       10233; 
        server_name  _;
        root   /usr/share/nginx/nextcloud_server;
        index  index.php index.html /index.php$request_uri;

        client_max_body_size 512M;
    	client_body_timeout 300s;
    	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/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;

    	# Pagespeed is not supported by Nextcloud, so if your server is built
    	# with the `ngx_pagespeed` module, uncomment this line to disable it.
    	#pagespeed off;

    	# 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;

    	# Remove X-Powered-By, which is an information leak
    	fastcgi_hide_header X-Powered-By;
	
	location = / {
        	if ( $http_user_agent ~ ^DavClnt ) {
            		return 302 /remote.php/webdav/$is_args$args;
        	}
    	}

    	location = /robots.txt {
        	allow all;
        	log_not_found off;
        	access_log off;
   	}

	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(?:$|/) {
        # Required for legacy support
        rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

        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 127.0.0.1:9000;

        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;

        fastcgi_max_temp_file_size 0;
    }

    location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        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 ~ \.wasm$ {
            default_type application/wasm;
        }
    }

    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;
    }

}

# 访问并安装

  • 浏览器输入10233端口,首次执行安装;
  • 安装过程中,可能会报超时,这是正常的,再次访问可以进入登录界面;
  • 首次访问,可能没有加载应用商店(不知道是缓存问题,还是配置问题)。 修改config.php, 添加配置:
'appstoreenabled' => true

# 参考文档

  • 官网文档,在centos安装-https://docs.nextcloud.com/server/23/admin_manual/installation/example_centos.html
  • 官方文档,ng配置-https://docs.nextcloud.com/server/23/admin_manual/installation/nginx.html
  • linux-ng运行 php, nextcloud-https://blog.51cto.com/u_16213581/10262076