搭建自己的网盘Nextcloud

搭建自己的网盘Nextcloud

报错:
PHP module dom not installed. 
 
Please ask your server administrator to install the module. 
 
PHP module XMLWriter not installed. 
 
Please ask your server administrator to install the module. 
 
PHP module XMLReader not installed. 
 
Please ask your server administrator to install the module. 
 
PHP module mb multibyte not installed. 
 
Please ask your server administrator to install the module. 
 
PHP module GD not installed. 
 
Please ask your server administrator to install the module. 
 
PHP modules have been installed, but they are still listed as missing? 
 
Please ask your server administrator to restart the web server.
解决
#PHP module mb multibyte
yum -y install php72w-mbstring

#PHP module dom
yum -y install php72w-dom

#PHP module XMLWriter
yum -y install php72w-xmlwriter

#PHP module GD
yum -y install php72w-gd

#PHP module XMLReader
yum -y install php72w-xmlreader


#查看已安装的php扩展
php-m

centos7搭建Nextcloud

  • 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
  • 关闭selinux
vim /etc/selinux/config
selinux修改disabled
SELINUX=disabled

临时关闭:
setenforce 0

安装nginx

  • 搭建nginx

    默认情况下centos7.6没有nginx的源,需要配置Nginx官网提供Gentos的源地址。

  • 配置nginx

[root@hl-web lnmp-wordpress]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

[root@hl-web ~]# yum search nginx
  • 安装nginx
[root@hl-web ~]#  yum install -y pcre-devel openssl-devel #安装nginx依赖包
[root@hl-web ~]# yum install -y nginx

安装php

  • 启动php-fpm并设置开机自启
[root@hl-web ~]# systemctl start nginx
[root@hl-web ~]# systemctl enable nginx
  • 配置php
    [root@hl-web ~]# rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
    [root@hl-web ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
  • 安装php-fpm所属需要的包
    [root@hl-web ~]# yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
    
    [root@hl-web ~]#yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-intl
    
    
  • 启动php-fpm并设置开机自启
    [root@hl-web ~]# systemctl start php-fpm.service
    [root@hl-web ~]# systemctl enable php-fpm.service
    
  • 修改php-fpm配置文件
    vim /etc/php-fpm.d/www.conf
    
    #Line 8-10
    user = nginx
    group = nginx
    #Line 22
    listen = 127.0.0.1:9000
    #Line 366-370
    env[HOSTNAME] = $HOSTNAME
    env[PATH] = /usr/local/bin:/usr/bin:/bin
    env[TMP] = /tmp
    env[TMPDIR] = /tmp
    env[TEMP] = /tmp
    
    
  • 下一步,创建一下session目录,并且修改权限。
    mkdir -p /var/lib/php/session
    chown nginx:nginx -R /var/lib/php/session/ 
    

安装Mysql

  • 1 下载并安装MySQL**官方的 **Yum Repository
    [root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    

    ** 使用上面的命令就直接下载了安装用的Yum Repository,大概25KB的样子,然后就可以直接yum安装了。**

    [root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
    

    ** 之后就开始安装**MySQL服务器。

    [root@localhost ~]# yum -y install mysql-community-server
    

    ** 这步可能会花些时间,安装完成后就会覆盖掉之前的mariadb。**

    搭建自己的网盘Nextcloud

    至此MySQL就安装完成了,然后是对MySQL的一些设置。

    **2 **MySQL数据库设置

    ** 首先启动**MySQL

    [root@localhost ~]# systemctl start  mysqld.service
    

    ** 查看**MySQL运行状态,运行状态如图:

    [root@localhost ~]# systemctl status mysqld.service
    

    搭建自己的网盘Nextcloud

    ** 此时**MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:

    [root@localhost ~]# grep "password" /var/log/mysqld.log
    

    搭建自己的网盘Nextcloud

    ** 如下命令进入数据库:**

    [root@localhost ~]# mysql -uroot -p
    

    密码有安全限制。可以通过如下命令修改:

    mysql> set global validate_password_policy=0;
    mysql> set global validate_password_length=1;
    

    然后可以改密码了

    set password='new password'
    

    修改权限

    然后运行下面两条命令。
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
    其中123456换成你的密码。
    刷新权限
    flush privileges;
    
    最后就成功了。
    

    设置之后就是我上面查出来的那几个值了,此时密码就可以设置的很简单,例如1234之类的。到此数据库的密码设置就完成了。

    ** 但此时还有一个问题,就是因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:**

    [root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
    

    ** 此时才算真的完成了。 **

生成SSL证书

此步骤不一定必须,但是为了后面配置文件一致,所以一并配置。

证书的申请可以去网上腾讯云或者其它的平台申请免费的证书,此处使用openssl生成自定义证书。

推荐大家去腾讯云生成一个免费的证书,每次有效期是一年的时候。

#创建文件证书的目录
mkdir -p /etc/nginx/cert/
# 生成证书
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
#修改权限 
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/* 

安装和配置nextcloud

#安装解压缩软件
yum install unzip 

#下载,此处链接可以直接打开,选择最新版本14.0.3
wget --no-check-certificate https://download.nextcloud.com/server/releases/nextcloud-14.0.3.zip


#解压
unzip nextcloud-14.0.3.zip

#移动到nginx的root目录
mv nextcloud/ /usr/share/nginx/html/

#创建一个存放文件的Data目录
cd /usr/share/nginx/html/
mkdir -p nextcloud/data/

#变更 nextcloud 目录的拥有者为 nginx 用户和组
chown nginx:nginx -R nextcloud/

此处的nginx用户可以根据实际的需要,只有设置了用户组才能够进行安装,否则无法出现安装的页面。
能够出现下面的安装配置页面,那么基本上也就成功了。
接着我们来配置nginx,先创建配置文件。
cd /etc/nginx/conf.d/
vi nextcloud.conf 

在这里一定注意几个地方,比如server的监听方式,要与php-fpm中的配置保持一致。至于域名可以使用自己的内部域名。

upstream php-handler {
    server 127.0.0.1:9000;
 #server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name 192.168.0.124;
 # enforce https
 return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name 192.168.0.124;

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

#检测配置成功之后,可以启动服务
systemctl restart nginx 
systemctl restart php-fpm 

最后我们输入http://域名,或者IP来打开安装界面完成配置安装 ,使用之前配置的域名打开,出现安装界面。

  1. 设置管理员账号
  2. 选择文件存放目录
  3. 配置选择数据库

点击完成安装,稍等几分钟之后便跳转到首页。

上一篇:docker 安装nextcloud+onlyoffice+mysql


下一篇:对于ESC服务器的使用体验