ウェブサイト検索

openSUSE Leap 42.2 に ownCloud 9.1.4 をインストールして構成する


導入

ownCloud は、Dropbox と同様、オープンソースのファイル同期および共有ソフトウェアです。ファイルをローカル共有ディレクトリに配置するだけで、それらのファイルは、ownCloud デスクトップ同期クライアント、Android アプリ、または iOS アプリを使用してサーバーや他のデバイスにすぐに同期されます。

このチュートリアルでは、openSUSE 42.2 に ownCloud のサーバー側をインストールして構成する方法を説明します。

はじめる

まずはSuSEfirewall2をインストールします。これは、に保存されている設定から iptables ルールを生成するスクリプトです。

/etc/sysconfig/SuSEfirewall2

。 Zipper を使用してインストールします。

zypper in SuSEfirewall2

YaST 構成モジュールもありますが、すべてのファイアウォール設定を構成できるわけではないため、構成ファイルを手動で編集する必要があります。

$EDITOR /etc/sysconfig/SuSEfirewall2

そこで検索してください

FW_SERVICES_EXT_TCP

次のように変更します。

FW_SERVICES_EXT_TCP="22 80 443"

これらは、ssh、http、https ポートです。
保存して終了。

次に、それを起動し、起動時に起動できるようにします。

systemctl start SuSEfirewall2
systemctl enable SuSEfirewall2

再起動

sshd

:

systemctl restart sshd

NGINX をインストールする

NGINX は openSUSE リポジトリでも利用できるため、次のようになります。

zypper in nginx

起動して有効にします。

systemct start nginx
systemctl enable nginx

MariaDB のインストール

NGINX と同様に、MariaDB は openSUSE パッケージとしても利用できるため、次のようになります。

zypper in mariadb mariadb-client

次 :

systemctl start mysqld
systemctl enable mysqld

root アカウントを構成します。

mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Reload privilege tables now? [Y/n]

これで、MariaDB シェルにログインして、ownCloud に使用される新しいデータベースとユーザーを作成できるようになりました。

mysql -u root -p

データベース システム シェル:

mysql> CREATE DATABASE myownclouddb;
mysql> CREATE USER 'ocuser'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON 'myownclouddb.*' TO 'ocuser'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

これで、MariaDB が ownCloud 用に正しく構成されました。

PHP-FPMをインストールする

ownCloud には PHP 5.4 以降が必要です。 PHP-FPM をインストールします。これは、訪問者の多いサイトを処理する場合に便利な FastCGI の代替手段です。このガイドでは PHP7 を使用します。
ジッパーを通して:

zypper in php7-fpm php7-gd php7-mysql php7-mcrypt php7-curl php7-pear php7-zip php7-json php7-ldap

次に、デフォルトの php-fpm 構成ファイルをコピーし、次のコマンドを実行します。

cd /etc/php7/fpm
cp php-fpm.conf.default php-fpm.conf

テキスト エディタでそのファイルを開きます。

$EDITOR php-fpm.conf

そこで、次の行を探します (そして次のように変更します)。

error_log = log/php-fpm.log
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

保存して終了します。
さあ、修正してください

php.ini

:

$EDITOR /etc/php7/cli/php.ini

761 行目のコメントを解除し、その値を変更します。

cgi.fix_pathinfo=0

このファイルを保存して終了し、次の場所にコピーします

conf.d

:

cp php.ini /etc/php7/conf.d/

PHP7のセッションディレクトリは、

/var/lib/php7

。所有者を nginx ユーザーに変更します。

chown -R nginx:nginx /var/lib/php7/
PHP-FPM と連携するように NGINX を構成する

新しい NGINX 構成ファイルを作成し、古いファイルのバックアップを作成します。

cd /etc/nginx
cp nginx.conf nginx.conf.bk
$EDITOR nginx.conf

65 行目に、次の構成を追加します。

 location ~ \.php$ {
                root /srv/www/htdocs;
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       }

保存して終了し、nginx をテストします。

nginx -t

次の行を読む必要があります。

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

最後に:

systemctl start php-fpm
systemctl enable php-fpm
systemctl restart nginx

ownCloudをインストールする

Web ルート ディレクトリに移動します。

/srv/www

そして、そこからownCloudをダウンロードします。

wget https://download.owncloud.org/community/owncloud-9.1.4.tar.bz2

アーカイブを抽出します。

tar xf owncloud-9.1.4.tar.bz2

の中に

owncloud

抽出したフォルダーを作成し、新しいデータ ディレクトリを作成し、その所有者を nginx ユーザーに変更します。

mkdir owncloud/data
chown -R nginx:nginx owncloud/
ownCloud の仮想ホストを構成する

次のステップは、ownCloud 用に NGINX で仮想ホストを構成することです。

mkdir /etc/nginx/vhosts.d && cd /etc/nginx/vhosts.d

そこで、新しいファイルを作成します。

$EDITOR owncloud.conf

そのファイルに次の内容を貼り付けます。

upstream php-handler {
  #server 127.0.0.1:9000;
  server unix:/var/run/php-fpm.sock;
}

server {
  listen 80; # If you have a SSL certificate (Recommended), change this line with "listen 443 ssl;" and add certificate lines;
  server_name storage.mydomain.com;

  # Path to the root of your installation
  root /srv/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/ =404;
  }

  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;
    fastcgi_intercept_errors on;
  }

  # Adding the cache control header for js and css files
  # Make sure it is BELOW the location ~ \.php(?:$|/) { block
  location ~* \.(?:css|js)$ {
    add_header Cache-Control "public, max-age=7200";
    # Add headers to serve security related headers
    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;
    # Optional: Don't log access to assets
    access_log off;
  }

  # Optional: Don't log access to other assets
  location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
    access_log off;
  }
}

サービスを保存、終了、再起動します。

systemctl restart nginx
systemctl restart php-fpm
systemctl restart mysql

結論

これでサーバー側が適切に構成されました。最後のステップでは、Web ブラウザで http://storage.mydomain.com にアクセスし、グラフィカル構成を完了します。このプロセスが完了すると、ownCloud ダッシュボードが完全に利用できるようになります。

関連記事: