之前在 Debian 服务器上搭建了ownCloud,下面在 CentOS 上做一遍,步骤稍有不同。
配置 LNMP
具体步骤见:CentOS 搭建 LNMP 环境
安装依赖的 PHP 模块
sudo yum install php-gd php-mbstring php-pear-MDB2-Driver-mysqli php-pear-Net-Curl php-process php-xml php-zipstream php-intl php-mcrypt php-pecl-imagick
下载并解压 ownCloud
wget https://download.owncloud.org/community/owncloud-6.1.0.tar.bz2
tar -jxf owncloud-6.1.0.tar.bz2
cp -r owncloud/* /path/to/your/webservers/document-root
记得修改文件权限:
cd /path/to/your/webservers/document-root/
mkdir data tmp
sudo chown -R nginx:nginx config data apps tmp
配置 Nginx
按照官方安装文档上的说明编辑 Nginx 的 server 配置块:
server {
listen 443 ssl;
server_name cloud.example.com;
ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
root /var/www/;
client_max_body_size 10G; # set max upload size
fastcgi_buffers 64 4K;
rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
deny all;
}
location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ index.php;
}
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$1;
fastcgi_param PATH_INFO $2;
fastcgi_param HTTPS on;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}
# Optional: set long EXPIRES header on static assets
location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
# Optional: Don't log access to assets
access_log off;
}
}
然后重启 Nginx:
sudo service nginx restart
配置 MySQL
登陆 MySQL:
mysql -u root -p
创建用户cloud
:
create user 'cloud'@'localhost' identified by 'password';
创建数据库 cloud
,并授权用户 cloud
拥有此数据库的所有权限:
create database cloud;
grant all privileges on cloud.* to 'cloud'@'localhost' identified by 'passwd';
flush privileges;
进入 ownCloud 安装界面
在浏览器中打开 https://yourdomain.com/,即可进入 ownCloud 的安装界面。
首先需要建立一个管理员账号,输入用户名和密码即可。点击高级
,可以看到数据库配置选项,选择 MySQL,数据库名填 cloud
,用户名填 cloud
,密码填刚才设定的密码。最后点 Finish
完成安装过程
修改上传限制
默认上传文件最大为 2M,显然太小了,下面改成 1024M。
编辑 /etc/php5/fpm/php.ini
:
upload_tmp_dir = /path/to/your/webservers/document-root/tmp
upload_max_filesize = 1024M
post_max_size = 1024M
然后重启 php-fpm
:
sudo service php-fpm restart