什么是Nextcloud
Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或团队的云同步网盘,从而实现跨平台跨设备文件同步、共享、版本控制、团队协作等功能。它的客户端覆盖了Windows、Mac、Android、iOS、Linux 等各种平台,也提供了网页端以及 WebDAV接口,所以你几乎可以在各种设备上方便地访问你的云盘。
Nextcxloud的部署方式
Nextcloud的服务端部署方式主要有两种(基于LNMP和基于Docker),读者可以根据自己情况进行选择一种部署方式。服务器需要是Linux操作系统,你可以在本地安装一个虚拟机进行测试,然后再到云服务器上部署。Mac系统理论上支持,可以参考Linux教程来操作。Ubuntu系统支持snap一键安装,甚至安装系统时都提供安装nextcloud的选项。本文主要介绍CentOS 7环境下基于LNMP部署Nextcloud的方法。
yum remove -y php*
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum -y --enablerepo=remi install php81-php php81-php-fpm php81-php-bcmath php81-php-ctype php81-php-curl php81-php-dom php81-php-gd php81-php-hash php81-php-iconv php81-php-intl php81-php-mbstring php81-php-pdo_mysql php81-php-simplexml php81-php-soap php81-php-xsl php81-php-zip php81-php-xml php81-php-sockets php81-php-session php81-php-snmp php81-php-mysql php81-php-cli php81-php-json php81-php-mcrypt php81-php-mysqlnd php81-php-pecl-crypto php81-php-pecl-mcrypt php81-php-pecl-geoip php81-php-recode php81-php-xml
#在安装的过程中要仔细检查每一个php扩展是否安装成功,如果有安装不成功的扩展需要及时重装。如果没有及时重装可能会导致服务器内部错误。
#如果php-mysqlnd提示安装失败,换个源试试,php-mysqlnd没装上web安装必失败。
设置软连接
ln -s /opt/remi/php81/root/usr/bin/php /usr/bin/php
php -v
#php命令
systemctl status php-fpm #查看php状态
systemctl start php #启动php
systemctl stop php-fpm #停止php
systemctl restart php-fpm #重启php
systemctl enable php-fpm #配置php自启动
此处采用最简便的yum安装方式
yum install -y nginx
启动nginx
systemctl start nginx
首先先将防火墙、selinux关闭
1)安装必要的软件包
# yum -y groupinstall "Development Tools"
# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
# rpm -ivh mysql80-community-release-el7-1.noarch.rpm2)修改安装mysql的yum源文件
# vim /etc/yum.repos.d/mysql-community.repo (把gpgcheck的值改为0)
# yum -y install mysql-community-server
# systemctl start mysqld && systemctl enable mysqld
# grep "password" /var/log/mysqld.log3)登录数据库
# mysql -uroot -p"%i+g10uS.dre"
mysql> exit4)修改数据库密码
mysql>alter user 'root'@'localhost' identified by "Li*@djfin...";
Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)可以重新创建一个用户提供给nextcloud使用
create user nextcloud@localhost identified by '@Qwer123456';
创建数据库
create database nextcloud;
授权
grant all on nextcloud.* to nextcloud@localhost;
刷新权限
flush privileges;
wget https://download.nextcloud.com/server/releases/latest-27.zip
yum install -y unzip #安装unzip用来解压文件
uzip latest-27.zip #解压上面下载的zip文件
mv nextcloud /home/html # 将整个文件夹移动到你想要的目录,后期数据也会生成在nextcloud目录中,要确保磁盘的容量够大
#老规矩,如果有未找到命令的报错,就安装一下
#安装命令 yum -y install '名称'
chown -R apache:apache /home/html #把这一文件下的子文件、子目录的所有者设为apache用户
chmod -R 775 /home/html #赋予775权限
vim /etc/selinux/config #编辑selinux配置文件
#进去之后按i编辑,然后找到SELINUX的那一行
SELINUX=disbabled #把等号删掉,改为disabled然后重启,
如果只是想临时修改就执行以下命令(不用重启,但是重启后就失效了,需要重新设置)
sentenforce 0
server {
listen 10001;
server_name localhost; # 你的网站域名或IP地址
root /home/html; # 网站的根目录
access_log /home/wwwlog/filecoin-access.log ;
error_log /home/wwwlog/filecoin-error.log;
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;
add_header Referrer-Policy no-referrer;
add_header X-Content-Type-Options 'nosniff';
add_header X-Robots-Tag 'noindex, nofollow';fastcgi_hide_header X-Powered-By;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/nextcloud/remote.php/dav;
}
location = /.well-known/webfinger {
return 301 $scheme://$host:$server_port/nextcloud/index.php/.well-known/webfinger;
}
location = /.well-known/nodeinfo {
return 301 $scheme://$host:$server_port/nextcloud/index.php/.well-known/nodeinfo;
}
location /.well-known/acme-challenge { }location ^~ /nextcloud {
# set max upload size
client_max_body_size 512M;
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 /nextcloud {
rewrite ^ /nextcloud/index.php$request_uri;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
include fastcgi_params;
}location ~ ^\/nextcloud\/.+[^\/]\.(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /nextcloud/index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
add_header X-Content-Type-Options 'nosniff';
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;
add_header Referrer-Policy no-referrer;
add_header X-Robots-Tag 'noindex, nofollow';
# Optional: Don't log access to assets
access_log off;
}location ~ ^\/nextcloud\/.+[^\/]\.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /nextcloud/index.php$request_uri;
add_header X-Content-Type-Options 'nosniff';
add_header X-Robots-Tag 'noindex, nofollow';
add_header X-Permitted-Cross-Domain-Policies 'none';
# Optional: Don't log access to other assets
access_log off;
}
}
}
在浏览器输入https://网站IP/nextcloud,
如果这一步一直出现“内部错误”,多半是nextcloud和data目录的所有者不对造成的,尝试:
确保以上的权限设置都设置成功了
1. 如果实在没辙,尝试一下将nextcloud设为777
chmod -R 777 /home/html/nextcloud
数据目录会默认添加/home/html/nextcloud/data 这个我们可以不用管
然后就是数据库配置那一块,就把咱们之前创建的nextclou用户和密码以及nextcloud库名填写进去,最后就是端口那一块就填写: 127.0.0.1:3306
剩下的功能就是各位友友去探索了,其实之前有很多小类型的报错,无法复播,但是以上的步骤以及配置文件都是现成的,搭建起来的配置文件,所以遇到问题的时候可以评论区留言一下,一起探讨,
另外该篇文章参照两位博主的文章,仅对两位博主的文章进行整合,对部分错误进行修改,最后进行整合,以下为两位博主的文章链接,大家可以参考一下
全网最详细CentOS 7下部署最新版nextcloud教程_centos7搭建nextcloud-CSDN博客
[亲测] 私有云盘Nextcloud在nginx环境下安装(全流程)_error while trying to create admin user: failed to-CSDN博客