nextcloud命令版安装篇(小白推荐)

img

一款十分优秀的私人云盘(nextcloud)在这里强烈推荐,下面是安装方法:

1.将自带的epel、nginx、php全部卸载(rpm -e … –nodeps)

1
2
3
rpm -qa|grep php
rpm -qa|grep php-common
rpm -qa|grep nginx


2.安装各种依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
yum -y install epel-release
yum -y install nginx
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 这里的php版本可能会随着nextcloud的升级版本会不够用,如果版本过低,卸载重装最新版本就可以,教程度娘很多。
yum -y install php72w-fpm php72w-cli php72w-gd php72w-mysql php72w-pear php72w-xml php72w-mbstring php72w-pdo php72w-json php72w-pecl-apcu
php -v
vim /etc/php-fpm.d/www.conf // 编辑文本
以下是www.conf的内容
.....
user = nginx //将用户和组都改为nginx
group = nginx
.....
listen = 127.0.0.1:9000 //php-fpm所监听的端口为9000
......
env[HOSTNAME] = $HOSTNAME //去掉下面几行注释
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp


3.设置用户nginx

1
2
3
4
5
6
7
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
ll -d /var/lib/php/session/
systemctl start php-fpm
systemctl start nginx
systemctl enable php-fpm
systemctl enable nginx


4.安装并配置MariaDB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
接下来设置MariaDB的root密码
mysql_secure_installation //按照提示设置密码,首先会询问当前密码,密码默认为空,直接回车即可
Enter current password for root (enter for none): //直接回车
Set root password? [Y/n] Y
New password: //输入新密码
Re-enter new password: //再次输入新密码

Remove anonymous users? [Y/n] N
Disallow root login remotely? [Y/n] N
Remove test database and access to it? [Y/n] N
Reload privilege tables now? [Y/n] Y


5.为nextcloud设置数据库账户密码

1
2
3
4
5
6
7
mysql -p
MariaDB [(none)]> create database nextcloud_db;
MariaDB [(none)]> create user nextclouduser@localhost identified by 'nextcloudpasswd';
MariaDB [(none)]> grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextcloudpasswd';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
# 最终nextcloud数据库的用户名密码为:nextclouduser----nextcloudpasswd


6.为Nextcloud生成自签名SSL证书(最好有自己的签名证书,貌似这个已经失效了)

1
2
3
4
5
6
7
8
9
10
cd /etc/nginx/cert/
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
.....
Country Name (2 letter code) [XX]:cn //国家
State or Province Name (full name) []:beijing //省份
Locality Name (eg, city) [Default City]:beijing //地区名字
Organization Name (eg, company) [Default Company Ltd]:lucfzy //公司名
Organizational Unit Name (eg, section) []:Technology //部门
Common Name (eg, your name or your server's hostname) []:lucfzy //CA主机名
Email Address []:lucfzy@163.com


  1. 然后将证书文件的权限设置为660
    1
    2
    chmod 700 /etc/nginx/cert
    chmod 600 /etc/nginx/cert/*

8.下载并安装Nextcloud16.0.4,获取最新版nextcloud list。(强烈建议这种方式安装包,推荐迅雷下载,因为在线wget的速度会比较慢,可能是有墙的缘故吧)

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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
yum -y install wget unzip
cd /usr/local/src/
# 如果按照上述方式安装,这一步请忽略
wget https://download.nextcloud.com/server/releases/nextcloud-16.0.4.zip
# 直接解压即可
unzip nextcloud-16.0.4.zip
mv nextcloud /usr/share/nginx/html/
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/
chown nginx:nginx -R nextcloud/
ll -d nextcloud
cd /etc/nginx/conf.d/
vim nextcloud.conf
---
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}

server {
listen 80;
server_name nextcloud.kevin-inc.com;
# enforce https
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name nextcloud.kevin-inc.com;

ssl_certificate /etc/nginx/cert/nextcloud.crt;
ssl_certificate_key /etc/nginx/cert/nextcloud.key;

# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000;
includeSubDomains; preload;";
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;

# Path to the root of your installation
root /usr/share/nginx/html/nextcloud/;

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

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

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

# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;

# Disable gzip to avoid the removal of the ETag header
gzip off;

# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed 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 php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}

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

# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";
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;
# Optional: Don't log access to other assets
access_log off;
}
}


9.测试nginx服务器配置文件是否有问题,没有问题重启nginx

1
2
3
4
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl restart nginx


10.访问http域名即可。bingo~。

Tips:
1.完全卸载php

1
2
3
rpm -qa|grep php-common
rpm -qa|grep php
yum remove php*


2.php7.3安装教程,前提是没有安装过php,如果有安装过,请完全删除后自测。

1
2
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w-fpm php72w-cli php72w-gd php72w-mysql php72w-pear php72w-xml php72w-mbstring php72w-pdo php72w-json php72w-pecl-apcu

点滴分享,您的支持将鼓励我继续创作!