核心特性:
支持 Android、iOS 和桌面端访问文件。支持 Dropbox、S3 和 Google Docs 等外部存储。供应历史版本支持,可以规复意外删除的文件。安装条件1 台 CentOS 7 云做事器1 个具有 root 权限的账号运行 ownCloud 的内存哀求很低,但官方哀求至少 128MB 内存,建议 512MB 内存。由于我们搭建的私人云盘,512MB 内存能支持 10 用户并发,已足够我们利用。
首先,下载 MySQL rpm 包,利用本地安装办法下载安装包及依赖包:

yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
然后,安装 mysql-community-server 软件包,启动 MySQL 并找到随机密码:
# 安装 MySQLyum install mysql-community-server# 启动 MySQLsystemctl start mysqld# 查找安装时天生的随机密码[root@ownCloud ~]# grep -i password /var/log/mysqld.log2023-09-03T07:04:16.666834Z 1 [Note] A temporary password is generated for root@localhost: aiwfrtTl7-=2
接着,我们利用随机密码登录 MySQL,创建 ownCloud 库和 ownCloud 用户并做好授权:
# 创建 ownCloud 库mysql> CREATE DATABASE owncloud DEFAULT CHARACTER SET utf8mb4;# 新建 ownCloud 用户mysql> CREATE USER owncloud@'%' IDENTIFIED BY 'owncloud';# 授权mysql> grant all privileges on owncloud. to owncloud@'%' identified by 'owncloud';# 刷新授权mysql> flush privileges;
安装和配置 PHP7(FPM)添加 php7-fpm 库
网上有很多 PHP7 库,我们这里利用 webtatic 库:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装 php7-fpm 和 ownCloud 依赖的软件包
接着我们安装 php7-fpm 和一些用于 ownCloud 安装的依赖软件包:
yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-intl php-pecl-zip
若提示 “失落败的软件包是:mysql-community-libs-compat-5.7.43-1.el7.x86_64”,请利用rpm --import [https://repo.mysql.com/RPM-GPG-KEY-mysql-2022](https://repo.mysql.com/RPM-GPG-KEY-mysql-2022)命令办理。
检讨 PHP 版本确保安装成功:
[root@owncloud tmp]# php -vPHP 7.4.33 (cli) (built: Aug 1 2023 09:00:17) ( NTS )Copyright (c) The PHP GroupZend Engine v3.4.0, Copyright (c) Zend Technologies
配置 php7-fpm我们将配置 php-fpm 与 nginx 一块运行。php7-fpm 将在 nginx 用户下运行,并监听 9000 端口。 利用 vim 编辑默认的 php7-fpm 配置:
vim /etc/php-fpm.d/www.conf
在第 24 行和第 26 行中,将 user 和 group 变动为 nginx。
user = nginxgroup = nginx
查看第 38 行,确保 php-fpm 在 9000 端口运行。
listen = 127.0.0.1:9000
取消第 396-400 行的注释,开启 php-fpm 系统环境变量。
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
保存文件并退出编辑器。接下来,在 /var/lib/ 目录中为 session 创建一个新目录,并将目录所有者变动为 nginx 用户。
mkdir -p /var/lib/php/session chown nginx:nginx -R /var/lib/php/session/
启动 php-fpm启动 php-fpm,然后将其添加到开机自启动。
systemctl start php-fpm systemctl enable php-fpm
至此,php7-fpm 配置已完成。
安装和配置 Nginx添加 Nginx 官方 yum 库添加 Nginx 官方 yum 源 /etc/yum.repos.d/nginx.repo 文件中添加以下内容,设置 nginx yum 源:
[nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.key[nginx-mainline]name=nginx mainline repobaseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/gpgcheck=1enabled=0gpgkey=https://nginx.org/keys/nginx_signing.key
安装 Nginx
yum install -y nginx
启动并设置开机启动
systemctl start nginx systemctl enable nginx
安装 ownCloud下载 ownCloud我们利用 wget 命令下载 ownCloud,因此须要先安装 wget 包。其余,我们还须要安装 unzip 包用于解压缩 zip 文件。
yum -y install wget unzip
进入 /tmp 目录并利用 wget 从 ownCloud 站点下载最新稳定的 ownCloud 10.13 压缩包:
cd /tmpwget --no-check-certificate https://download.owncloud.com/server/stable/owncloud-10.13.0.zip
解压 owncloud-10.13.0.zip 文件并将其移动到 /usr/share/nginx/html/ 目录:
unzip owncloud-10.13.0.zipmv owncloud/ /usr/share/nginx/html/
接下来,转到 nginx Web 根目录并为 owncloud 创建一个新的 data 目录。
cd /usr/share/nginx/html/ mkdir -p owncloud/data/
将 owncloud 目录的所有者变动为 nginx 用户和组。
chown nginx:nginx -R owncloud/
配置 OwnCloud1). 天生自署名 SSL 证书
我们将在的 https 连接下运行 owncloud。您可以利用免费的 SSL 证书,例如 let's encrypt。在本文中,我将利用 OpenSSL 命令创建我自己的 SSL 证书文件。为 SSL 文件创建一个新目录:
mkdir -p /etc/nginx/cert/
然后利用下面的 OpenSSL 命令天生新的 SSL 证书文件:
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key
按照 OpenSSL 命令的哀求输入 SSL 证书的详细信息。然后用 chmod 命令将所有证书文件的权限改为 600。
chmod 600 /etc/nginx/cert/
2). 在 Nginx 中配置 ownCloud 虚拟主机
在1.下载 ownCloud 步骤中,我们下载了 ownCloud 源代码并将其配置为在 Nginx Web 做事器下运行。但我们仍旧须要为 ownCloud 配置虚拟主机。 在 /etc/nginx/conf.d/ 目录中创建一个新的虚拟主机配置文件 owncloud.conf:
cd /etc/nginx/conf.d/ vim owncloud.conf
添加以下虚拟主机配置:
upstream php-handler { server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock;} server { listen 80; server_name data.owncloud.co; # enforce https return 301 https://$server_name$request_uri;} server { listen 443 ssl; server_name data.owncloud.co; ssl_certificate /etc/nginx/cert/owncloud.crt; ssl_certificate_key /etc/nginx/cert/owncloud.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=15552000; includeSubDomains"; 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/owncloud/; 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; } location /.well-known/acme-challenge { } # 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)/ { return 404; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; } location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on; fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice 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 $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=15552000; includeSubDomains"; 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; }}
保存文件并退出编辑器。
末了,测试 nginx 配置无误,然后重新启动 nginx。
# 验证 nginx 配置是否有误nginx -t# 重新启动 nginxsystemctl restart nginx
配置 SELinux 和 firewalld我们将使 SELinux 保持在逼迫模式下,因此我们须要 SELinux 管理工具包来配置它。利用 yum 命令安装 SELinux 管理工具:
yum -y install policycoreutils-python
然后以 root 身份实行以下命令,以许可 ownCloud 在 SELinux 下运行。请记住变动 ownCloud 目录,以防您利用不同的目录进行 ownCloud 安装:
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/data(/.)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/config(/.)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/apps(/.)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/assets(/.)?' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/.htaccess' semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/html/owncloud/.user.ini' restorecon -Rv '/usr/share/nginx/html/owncloud/'
接下来,启动 firewalld 做事并打开 owncloud 的 HTTP 和 HTTPS 端口。
# 启动 firewalld 做事systemctl start firewalld# 开启 firewalld 做事自启动systemctl enable firewalld
利用 firewall-cmd 命令打开 HTTP 和 HTTPS 端口,然后重新加载防火墙使之立即生效。
firewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --add-service=httpsfirewall-cmd --reload
至此,做事器配置部分已完成。
ownCloud 安装引导现在,打开浏览器并输入 ownCloud 公网IP,我的IP是:xxx.xxx.xxx.xxx,您将被重定向到安全的 HTTPS 连接。设置管理员的用户名和密码,然后输入数据库信息并单击完成设置,等待 OwnCloud 安装完成。
至此,Owncloud 已在 CentOS 7 做事器上成功安装 Nginx、php7-fpm 和 MySQL。
若提示 php zip 模块没有安装或者 intl 模块没有安装,请运行 yum -y install php-intl php-pecl-zip 命令安装