ubuntu server 安裝nextcloud12

1.更新系統安裝必要的依賴包php

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common nano wget

2.安裝MariaDB10以上版本,若是不清楚安裝的版本是否符合nextcloud要求,能夠到官網上查詢css

nextcloud官網:https://nextcloud.com/install/#html

MariaDB安裝與配置:mysql

[user]$ sudo apt-get install -y mariadb-server

安裝完畢之後,運行:nginx

[user]$ mysql_secure_installation

這個的主要目的是更新和配置數據庫,同時設置相應的root密碼,我在安裝的時候遇到一個問題就是在普通用戶下沒法成功鏈接到數據庫,須要切換到root進行,目前沒有解決這個問題,若是哪位大佬能夠解決,請給我留言.ajax

重啓MariaDB服務:sql

[user]$ sudo service mysql restart

登陸數據庫而且建立相應的數據庫數據庫

[user]$ mysql -uroot -p

*注意這一步若是登陸失敗,請切換root用戶執行json

建立數據庫:瀏覽器

MariaDB [(none)]> CREATE DATABASE nextcloud;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'strong_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

3.安裝php

[user]$ sudo apt-get -y install php-fpm php-cli php-json php-curl php-imap php-gd php-mysql php-xml php-zip php-intl php-mcrypt php-imagick php-mbstring

這裏設置的php memory爲512MB,upload_max_filesize 和 post_max_size 爲200M

[user]$ sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
[user]$ sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini
[user]$ sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/" /etc/php/7.0/fpm/php.ini
[user]$ sed -i "s/upload_max_filesize = .*/upload_max_filesize = 200M/" /etc/php/7.0/fpm/php.ini
[user]$ sed -i "s/post_max_size = .*/post_max_size = 200M/" /etc/php/7.0/fpm/php.ini

*配置文件的位置:

php:/etc/php/7.0/fpm/php.ini

配置PHP-FPM

配置文件使用默認的就好,若是有問題,請參考下面關於環境變量的配置

[user]$ sudo nano /etc/php/7.0/fpm/pool.d/www.conf

環境變量:

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

重啓PHP-FRM服務:

[user]$ sudo service php7.0-fpm restart

4.下載而且安裝NextCloud12

這裏將Nextcloud安裝到/var/www/nextcloud/目錄下,安裝目錄根據我的愛好就行

[user]$ wget https://download.nextcloud.com/server/releases/nextcloud-12.0.0.zip
[user]$ unzip nextcloud-12.0.0.zip
[user]$ sudo mkdir /var/www/
[user]$ sudo mv nextcloud /var/www/
[user]$ rm -f nextcloud-12.0.0.zip
[user]$ sudo chown -R www-data: /var/www/nextcloud

5.安裝和配置nginx

[user]$ sudo apt-get install nginx-extras nginx

6.這裏建立相應的ssl證書,方便你們訪問,若是有相應的證書,將證書放置/etc/nginx/ssl目錄下,若是是新手,請注意證書的名字

[user]$ sudo mkdir -p /etc/nginx/ssl
[user]$ cd /etc/nginx/ssl
[user]$ sudo openssl genrsa -des3 -passout pass:x -out nextcloud.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in nextcloud.pass.key -out nextcloud.key
[user]$ sudo rm nextcloud.pass.key
[user]$ sudo openssl req -new -key nextcloud.key -out nextcloud.csr
[user]$ sudo openssl x509 -req -days 365 -in nextcloud.csr -signkey nextcloud.key -out nextcloud.crt

7.

爲nginx服務器建立相應的配置文件:

[user]$ sudo nano /etc/nginx/sites-available/nextcloud

文件內容:

server {
    listen 80;
    server_name my.nextcloud.com;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl http2;
    server_name my.nextcloud.com;
    root /var/www/nextcloud;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/nextcloud.crt;
    ssl_certificate_key /etc/nginx/ssl/nextcloud.key;
    ssl_session_timeout 5m;
    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    access_log  /var/log/nginx/nextcloud.access.log;
    error_log   /var/log/nginx/nextcloud.error.log;

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

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

    client_max_body_size 512M;
    fastcgi_buffers 64 4K;
    gzip off;

    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

    location / {
        rewrite ^ /index.php$uri;
    }

    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/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        #Avoid sending the security headers twice
        fastcgi_param modHeadersAvailable true;
        fastcgi_param front_controller_active true;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri/ =404;
        index index.php;
    }

    location ~* \.(?:css|js)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=7200";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;
        # Optional: Don't log access to assets
        access_log off;
    }

    location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        access_log off;
    }

    location ~ /\.ht {
        deny all;
    }

}

注意:這裏須要更改相應的域名,不要直接複製

連接相應的配置文件:

[user]$ sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/nextcloud

重啓nginx服務:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

8.到此,安裝已經完成,接下來須要登陸nextcloud而且配置相應的文件存儲位置:

打開瀏覽器輸入:

 

8.https://my.nextcloud.com/install.php

注意這裏設置的域名,若是沒有設置域名,在相同的網段下使用IP進行訪問,我這裏在同一個路由下訪問nextcloud,主機的ip爲192.168.1.105,怎麼查看本身主機的ip方法有不少,命令也行,路由也行,怎麼方便怎麼來.

https://192.168.1.105/install.php

打開網頁後,設置相應的管理員用戶名和密碼及相應的文件存儲位置,這個位置能夠隨便設置,可是須要更改位置的組和擁有者爲www-data,

注意:上傳和下載大文件時可能會提示文件太大,須要更改上傳和下載文件最大限制:
配置文件須要修改:(1)./etc/php/7.0/fpm/php.ini 

php memory,upload_max_filesize 和 post_max_size

(2)./etc/nginx/sites-available/nextcloud

 client_max_body_size 1024M;

(3)/var/www/nextcloud/.htaccess

php_value upload_max_filesize
  php_value post_max_size
  php_value memory_limit

具體大小根據我的狀況設置

配置完成之後重啓相應的服務:

sudo systemctl restart php7.0-fpm sudo systemctl restart nginx
相關文章
相關標籤/搜索