本文適合有一些linux系統基礎的夥伴閱讀。
一 . 部署環境的系統是Centos7版本
[root@owncloud ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
二. 安裝並配置Nginx和php-fpm
[root@owncloud ~]# yum -y install epel-release
[root@owncloud ~]# yum -y install nginx
添加一個yum源來安裝php-fpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安裝相關組件
yum -y install php72w-fpm php72w-cli php72w-gd php72w-mcrypt php72w-mysql php72w-pear php72w-xml php72w-mbstring php72w-pdo php72w-json php72w-pecl-apcu php72w-pecl-apcu-devel
完成後,檢查一下php-fpm是否已正常安裝
[root@owncloud ~]# php -v
PHP 7.2.16 (cli) (built: Mar 10 2019 21:22:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies配置php-fpm
vim /etc/php-fpm.d/www.conf
.....
user = nginx //將用戶和組都改為nginx
group = nginx
.....
listen = 127.0.0.1:9000 //php-fpm所監聽的端口為9000
......
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/
啟動Nginx和php-fpm服務,並添加開機啟動
systemctl start php-fpm
systemctl start nginx
systemctl enable php-fpm
systemctl enable nginx
三. 安裝並配置MariaDB 或 mysql
題外話:Mariadb數據庫是原MySQL數據庫開發人員離開mysql後有開發的一款關係型數據庫,據說可以完全兼容MySQL數據庫。
使用MaraiDB作為owncloud數據庫。yum安裝MaraiDB服務
yum -y install mariadb mariadb-server
啟動MariaDB服務並添加開機啟動
systemctl start mariadb
systemctl enable mariadb
注意: 確保本地登陸數據庫的相關帳號及權限都OK。
Mysql需要設置為mixed模式:
set global binlog_format=mixed;
數據庫初始化設置。包括設置root用戶密碼,權限等。
mysql_secure_installatio
······
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
數據庫默認無密碼,根據實際情況確認參數設置
下面創建數據庫:
Mysql -uroot -p
MariaDB [(none)]> create database owncloud
MariaDB [(none)]> grant all privileges on owncloud.* to owncloud@localhost identified by '123456';
MariaDB [(none)]> flush privileges;
四. 配置owncloud生成自簽名SSL證書
當然也可以使用阿里雲或者騰訊雲上免費的SSL證書,但前提是你得有一個備案的域名才可以。
先為SSL證書創建一個新的文件夾:
cd /etc/nginx/cert/
penssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key
.....
Country Name (2 letter code) [XX]:cn //國家
State or Province Name (full name) []:sichuan //省份
Locality Name (eg, city) [Default City]:chengdu //地區名字
Organization Name (eg, company) [Default Company Ltd]:lxplwh //公司名
Organizational Unit Name (eg, section) []:Technology //部門
Common Name (eg, your name or your server's hostname) []:danteit //CA主機名
Email Address []:[email protected]
然後將證書文件的權限設置為660
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
五. 下載並安裝owncloud
wget https://download.owncloud.org/community/owncloud-10.1.1.zip
unzip owncloud-10.1.1.zi
mv owncloud /usr/share/nginx/html/
併為owncloud創建data目錄,將owncloud的用戶和組修改為nginx
mkdir -p owncloud/data/
chown nginx:nginx -R owncloud/
六. 配置Nginx虛擬主機
[root@owncloud ~]# vim /etc/nginx/nginx.conf
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream php-handler {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name owncloud.danteit.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name owncloud.danteit.com;
ssl_certificate /etc/nginx/cert/owncloud.crt;
ssl_certificate_key /etc/nginx/cert/owncloud.key;
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;
root /usr/share/nginx/html/owncloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
client_max_body_size 512M;
fastcgi_buffers 64 4K;
gzip 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;
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;
}
location ~* \.(?:css|js)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=7200";
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;
access_log off;
}
location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
access_log off;
}
}
確保沒有問題後重啟Nginx服務
[root@owncloud ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@owncloud ~]# systemctl restart nginx
七. 安裝owncloud
解析上面nginx中配置的域名owncloud.danteit.com,邦定hosts. 訪問http://owncloud.danteit.com進行owncloud界面安裝.
設置帳號密碼,以及數據庫的連接信息。如果不報錯,即可安裝完成,進入。
到此安裝完成。