owncloudは自家製dropboxのようなもの。
以下、メモ。
owncloudの構成
owncloudはphpで作られている。
そしてインタフェースはhttps。
したがって、動作にはowncloudのほかに、php, webサーバが必要。
さらにバックエンド用のデータベースソフトウェアも必要である。
packageのowncloud
owncloudはバックエンドのDBにMySQL, SQLiteなどが選べる。
個人用ならSQLiteでも大丈夫そうだが、packageに用意されているowncloudはMySQLが有効、SQLiteが無効になっている。
SQLite版owncloudが欲しければportsからコンパイルする必要がある。
これまた面倒なのでpackageのものを使った。
packageからowncloudをインストールすると、phpは勝手に入るが、webサーバ、MySQLは別にインストールする必要がある。
ここではwebサーバにnginxを選んだ。
ではMySQLは。
MySQLのバージョン選定
いや、MySQLはMySQLに決まっているんだが、実はpackageを探すと、5.1, 5.5, 5.6の三つがあるのだ。
1 2 3 4 |
$ pkg search "^mysql.*server" mysql51-server-5.1.73_2 mysql55-server-5.5.43 mysql56-server-5.6.24 |
果たしてどれを選べばよいのであろうか。
以上のURL他を見たところ、最新の5.6で良さそうなのでmysql56-server-5.6.24をインストールしておいた。
owncloudのインストール
packageで入れるだけ。
いっしょにnginx, mysql5.6も入れる。
1 |
# pkg install owncloud nginx mysql56-server |
MySQLの設定
owncloudのデータベースを受け持つMySQLの設定
システム起動時にMySQLも自動的に起動するように設定。
1 2 |
# sysrc mysql_enable=YES mysql_enable: -> YES |
すぐ起動
1 2 |
# service mysql-server start Starting mysql. |
mysql_secure_installationでセキュリティを高めておくと同時にスーパーユーザのパスワードも設定。
1 |
# mysql_secure_installation |
データベースの作成
USERはユーザ名に、CHANGE_THIS_PASSWORDはパスワードに書き換えること。
1 2 3 4 |
# mysql -p -e "create user 'USER'@'localhost' identified by 'CHANGE_THIS_PASSWORD';" # mysql -p -e "create database if not exists owncloud;" # mysql -p -e "grant all on owncloud.* to 'USER'@'localhost' identified by 'CHANGE_THIS_PASSWORD';" # mysql -p -e "flush privileges;" |
phpの設定
owncloudはphpで書かれている。そのphpの設定。
とはいえ、特別、何かすることはない。
/usr/local/etcにあるphp.ini-production を、php.ini としてコピー
次に/usr/local/etc/php/extensions.ini に以下の記載があることを確認する(デフォルトで記載があるはず)
1 2 |
extension=pdo.so extension=mysql.so |
php-fpmの設定
そのままでは静的コンテンツしか扱わないnginxが、phpを実行できるようにするための設定。
php-fpmがデーモンとして動作し、nginxからの要求に応じてphpを実行して結果を返す。
したがってphp-fpmとnginxがどう通信するかを規定したり、システム起動時にphp-fpmが自動的に起動するような指定が必要。
まずはphp-fpmの設定。
/usr/local/etc/php-fpm.confに以下があればよい。
それ以外はむしろ冗長だし、見にくくなるので削ってしまってよい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[global] pid = run/php-fpm.pid error_log = log/php-fpm.log [owncloud] listen=/var/run/php-fpm.socket listen.owner=www listen.group=www listen.mode=0666 listen.backlog=-1 listen.allowed_clients=127.0.0.1 user=www group=www pm=dynamic pm.max_children=4 pm.start_servers=1 pm.min_spare_servers = 1 pm.max_spare_servers = 2 pm.max_requests = 500 env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp |
システム起動時のphp-fpm起動設定
/etc/rc.conf内ではphp-fpmではなくphp_fpmとなることに注意(ハイフンではなくアンダースコア)
1 2 |
sysrc php_fpm_enable=YES php_fpm_enable: -> YES |
nginxの設定…の前に、SSLの準備
SSLのためにはサーバの鍵が必要。
手前味噌だが、ここにあるスクリプトを使ってくれい。
秘密鍵、証明書、DHパラメータ、三つのファイルを作成して、/usr/local/etc/sslあたりに入れる。
nginxの設定
以下、二つのサイトを参考にしつつ作成。
https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx-1.8.0&openssl=1.0.1l&hsts=yes&profile=intermediate
https://doc.owncloud.org/server/7.0/admin_manual/installation/nginx_configuration.html
出来たのが以下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; return 301 https://$server_name$request_uri; } upstream php-handler { #server 127.0.0.1:9000; #server unix:/var/run/php5-fpm.sock; server unix:/var/run/php-fpm.socket; } server { listen 443 ssl; server_name localhost; # # Generated with; # https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=nginx- 1.8.0&openssl=1.0.1l&hsts=yes&profile=intermediate # # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate ssl_certificate /usr/local/etc/ssl/server.crt; ssl_certificate_key /usr/local/etc/ssl/server.key; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits ssl_dhparam /usr/local/etc/ssl/dhparam.pem; # intermediate configuration. tweak to your needs. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RS A-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES 128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA- AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECD HE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-D SS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA- DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256 :AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!D ES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA '; ssl_prefer_server_ciphers on; # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months) add_header Strict-Transport-Security max-age=15768000; # OCSP Stapling --- # fetch OCSP records from URL in ssl_certificate and cache them ssl_stapling on; ssl_stapling_verify on; ## verify chain of trust of OCSP response using Root CA and Intermediate certs ssl_trusted_certificate /usr/local/etc/ssl/cert.pem; # end of generated # # copyed from https://doc.owncloud.org/server/7.0/admin_manual/installation/ngi nx_configuration.html # # Path to the root of your installation root /usr/local/www/owncloud/; # set max upload size client_max_body_size 10G; 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; 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 ~ ^/(?:\.htaccess|data|config|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(?:$|/) { 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_pass php-handler; } # 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の起動設定とサービススタート
1 2 |
# sysrc nginx_enable=YES nginx_enable: -> YES |
nginx, php-fpmを起動し、https://<サーバアドレス>にブラウザで繋げばOK
1 2 |
# service php-fpm start # service nginx start |
その他参考
https://doc.owncloud.org/server/7.0/admin_manual/configuration/database_configuration.html
No tags for this post.