owncloud安装配置笔记

date: 2017.05.05; modification:2018.07.25

目录:

1 服务端安装

服务器: ubuntu 18.04

1.1 安装 MariaDB

MariaDB 是 MySQL 关系数据库管理系统的一个分支. MySQL 的原始开发人员在 Oracle 收购 MySQL 后提出的关注之后创建了 MariaDB.

sudo apt-get install mariadb-server mariadb-client
sudo systemctl enable mariadb.service

设置密码:

sudo mysql_secure_installation

并按照提示进行如下输入:

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password:           输入密码
Re-enter new password:  再次输入密码
Remove anonymous users? [Y/n]: Y                    # 删除匿名用户
Disallow root login remotely? [Y/n]: Y              # 禁止root用户远程登录
Remove test database and access to it? [Y/n]: Y     # 删除测试db
Reload privilege tables now? [Y/n]: Y

重启服务:

sudo service mariadb restart

创建 Owncloud 数据库

sudo mysql -u root -p
CREATE DATABASE owncloud;
CREATE USER 'ownclouduser'@'localhost' IDENTIFIED BY 'user_password_here';      # 创建ownclouduser并设置密码为user_password_here
GRANT ALL ON owncloud.* TO 'ownclouduser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

1.2 安装与配置 PHP

安装:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php7.1 php7.1-fpm php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-apcu php7.1-smbclient php7.1-ldap php7.1-redis php7.1-gd php7.1-xml php7.1-intl php7.1-json php7.1-imagick php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl
sudo apt-get install php-fpm php-mysql

配置:

sudo vim /etc/php/7.1/fpm/php.ini

根据需要配置如下项:

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
display_errors = Off
cgi.fix_pathinfo = 0

1.3 安装 Owncloud

wget https://download.owncloud.org/community/owncloud-10.0.8.zip
unzip owncloud-10.0.8.zip
sudo mv owncloud /var/www/html/owncloud

sudo chown -R www-data:www-data /var/www/html/owncloud/
sudo chmod -R 755 /var/www/html/owncloud/

1.4 安装配置 Nginx

安装:

sudo apt install nginx
sudo systemctl enable nginx.service     # 开机自启动, 如果本来就可以自启动, 就不需要该命令

配置:

sudo nano /etc/nginx/sites-available/owncloud

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/owncloud;
    index  index.php index.html index.htm;
    server_name  example.com www.example.com;
    client_max_body_size 4096M;                 # 单文件最大上传文件限制


    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(?:$|/) {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
         fastcgi_intercept_errors on;
         fastcgi_request_buffering off;
    }

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

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

保存并退出.

sudo ln -s /etc/nginx/sites-available/owncloud /etc/nginx/sites-enabled/
sudo service nginx restart

2 客户端安装

环境: Ubuntu 16.04.

sudo sh -c "echo 'deb http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04/ /' > /etc/apt/sources.list.d/owncloud-client.list"
sudo apt-get update
sudo apt-get install owncloud-client

如果update的时候报错:

W: GPG 错误:http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04  Release: 由于没有公钥,无法验证下列签名: NO_PUBKEY 4ABE1AC7557BEFF9
W: 仓库 “http://download.opensuse.org/repositories/isv:/ownCloud:/desktop/Ubuntu_16.04  Release” 没有数字签名。
N: 无法认证来自该源的数据,所以使用它会带来潜在风险。

解决方案:

gpg --keyserver keyserver.ubuntu.com --recv 4ABE1AC7557BEFF9
gpg --export --armor 21C022AA985E0E11 | sudo apt-key add -
sudo apt-get update

然后再install.