如何在 CentOS 7 上安装 ownCloud 9.1.4
介绍
OwnCloud 9.1.4是一款用于文件共享和数据同步的开源软件,在企业领域非常有用,具有易于使用的前端Web格式。
本教程是关于在 CentOS 7 上安装 ownCloud,并使用 Nginx 作为 Web 服务器。
安装 Nginx 和 PHP
首先,安装 Nginx。该 Web 服务器可在 EPEL 存储库中找到,因此只需按如下所示添加它:
yum install epel-release
进而:
yum install nginx
接下来,使用 webtatic 存储库安装 PHP-FPM(FastCGI Process Manager),该存储库是通过以下命令添加的:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
现在可以将 PHP 与 ownCloud 所需的其他包一起安装:
yum install php70w-fpm php70w-cli php70w-json php70w-mcrypt php70w-pear php70w-mysql php70w-xml php70w-gd php70w-mbstring php70w-pdo
为 Nginx 配置 PHP-FPM
PHP-FPM 配置是通过编辑 php7-fpm 配置文件来完成的:
$EDITOR /etc/php-fpm.d/www.conf
搜索包含“用户”和“组”的行并更改为:
user = nginx
group = nginx
向下滚动,查找“listen”行,并将内容更改为:
listen = 127.0.0.1:9000
接下来,取消注释以下有关环境变量的行:
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
保存并退出。
现在,是时候在其中创建一个新文件夹了
/var/lib/
,使用以下命令:
mkdir -p /var/lib/php/session
将其所有者更改为 nginx 用户:
chown nginx:nginx -R /var/lib/php/session/
启动 nginx 和 PHP-FPM:
sudo systemctl start php-fpm
sudo systemctl start nginx
添加在启动时启动(机器作为服务器的日常使用所需):
systemctl enable nginx
systemctl enable php-fpm
安装 MariaDB
MariaDB 在 CentOS 存储库中可用,因此安装它:
yum install mariadb mariadb-server
配置MariaDB root密码:
mysql_secure_installation
在此过程中,回答以下问题:
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
登录 MariaDB shell 为 ownCloud 创建新数据库和用户。在此示例中,my_owncloud_db 是数据库名称,ocuser 是其用户。密码是:my_strong_password。
因此,执行命令:
mysql -u root -p
进而:
mysql> CREATE DATABASE my_owncloud_db;
mysql> CREATE USER ocuser@localhost IDENTIFIED BY 'my_strong_password';
mysql> GRANT ALL PRIVILEGES ON my_owncloud_db.* to ocuser@localhost IDENTIFIED BY 'my_strong_passowrd';
mysql> FLUSH PRIVILEGES;
生成 SSL 证书
如果不存在,请为 SSL 文件创建一个新目录:
mkdir -p /etc/nginx/cert/
接下来,生成一个新的 SSL 证书文件:
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key
使用以下命令更改权限:
chmod 600 /etc/nginx/cert/*
下载自己的云
下载自己的云服务器:
wget https://download.owncloud.org/community/owncloud-9.1.4.zip
提取存档并将其移动到
/usr/share/nginx/html/
:
unzip owncloud-9.1.2.zip
mv owncloud/ /usr/share/nginx/html/
进入Nginx根目录;在那里,创建一个新的
data
ownCloud 目录:
cd /usr/share/nginx/html/
mkdir -p owncloud/data/
在 Nginx 中配置虚拟主机
使用以下命令创建虚拟主机配置文件:
$EDITOR /etc/nginx/conf.d/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 storage.example.com;
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 -t
这应该显示“语法正常”消息。
重新启动 Nginx:
systemctl restart nginx
结论
服务器端配置完成。最后要做的事情是使用 Web 浏览器访问您的 ownCloud 服务器 URL(本例中为 storage.example.com),并使用图形前端完成配置。通过创建新的管理员帐户并输入在前面的步骤中创建的数据库凭据来执行此操作。您的云存储服务现已可供日常使用!