Nextcloudは、無料の(オープンソースの)ドロップボックスのようなソフトウェアであり、ownCloudプロジェクトのフォークです。 NextcloudはPHPとJavaScriptで記述されており、MySQL / MariaDB、PostgreSQL、Oracleデータベース、SQLiteなどの多くのデータベースシステムをサポートしています。
デスクトップとサーバー間でファイルの同期を維持するために、NextcloudはWindows、Linux、Macデスクトップ用のアプリケーションと、AndroidとiOS用のモバイルアプリケーションを提供しています。
このチュートリアルでは、Nginx Webサーバー、PHP 7.3、およびMariaDBデータベースを使用してNextcloud17をCentOS8サーバーにインストールする方法を示します。 Nextcloudをインストールし、無料のLet'sEncryptSSL証明書で保護します。
前提条件
このガイドでは、2GBのRAM、25GBの空き容量、2CPUを搭載したCentOS8サーバーにNextcloudをインストールします。
私たちが行うこと:
- NginxWebサーバーをインストールする
- PHP-FPM7.3をインストールします
- PHP-FPM7.3を構成する
- MariaDBデータベースのインストールと構成
- SSLLetsencryptを生成する
- Nextcloud17をダウンロード
- Nextcloud用のNginx仮想ホストのセットアップ
- Nextcloud用にSELinuxをセットアップする
- Nextcloudのインストール後
まず、NginxWebサーバーをCentOS8サーバーにインストールし、firewalldでHTTPおよびHTTPSポートを開きます。
以下のdnfコマンドを使用して、AppStreamリポジトリからNginxをインストールします。
sudo dnf install nginx
インストールが完了したら、nginxサービスを開始し、システムブートに追加します。
systemctl start nginx
systemctl enable nginx
次に、以下のコマンドを使用してnginxサービスのステータスを確認します。
systemctl status nginx
nginxサービスがCentOS8サーバーで稼働していることを確認します。
次に、HTTPSサービスとHTTPSサービスをfirewalldに追加します。
以下のfirewall-cmdコマンドを使用して、HTTPおよびHTTPSサービスをfirewalldに追加します。
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
その後、firewalldサービスをリロードします。
firewall-cmd --reload
その結果、Nginx Webサーバーが正常にインストールされ、CentOS8サーバーでHTTPポートとHTTPSポートが開かれました。
Nextcloudのシステム要件によると、インストールにはPHP7.2またはPHP7.3を使用することをお勧めします。
このガイドでは、REMIリポジトリからインストールできるPHP7.3を使用します。
先に進む前に、「PowerTools」リポジトリを有効にし、CentOS8サーバー用のEPELおよびREMIリポジトリを追加します。
以下のdnfコマンドを実行します。
sudo dnf config-manager --set-enabled PowerTools
sudo dnf install epel-release
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
次に、システムで利用可能なすべてのリポジトリを確認します。
dnf repolist
そして、以下のような結果が得られます。
「PowerTools」リポジトリを有効にし、CentOS8用のEPELおよびREMIリポジトリを追加しました。
次に、PHP7.3REMIリポジトリを有効にします。
PHPパッケージで利用可能なすべてのモジュールを確認してください。
dnf module list php
次に、PHP7.3REMIリポジトリのモジュールを有効にします。
dnf module enable php:remi-7.3
その後、以下のdnfコマンドを使用して、Nextcloud用のPHPおよびPHP-FPM7.3パッケージをインストールします。
sudo dnf install php-fpm php-cli php-devel php-gd php-mysqlnd php-pear php-xml php-mbstring php-pdo php-json php-pecl-apcu php-pecl-apcu-devel php-pecl-imagick-devel php-intl php-opcache php-zip
そして、PHPとPHP-FPM7.3をCentOS8システムにインストールしました。
ステップ3-PHP-FPM7.3を構成する
このステップでは、Nextcloudデプロイメント用にPHP-FPMをセットアップします。
次のコマンドを使用して、「php.ini」構成を編集します。
vim /etc/php.ini
コメントを外して、以下のように構成を変更します。
memory_limit = 512M
date.timezone = Asia/Jakarta
cgi.fixpathinfo = 0
保存して閉じます。
次に、PHPopcache構成'/etc/php.d/10-opcache.ini'を編集します。
vim /etc/php.d/10-opcache.ini
以下のように構成を変更します。
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
保存して閉じます。
次に、PHP-FPM構成'/etc/php-fpm.d/www.conf'を編集します。
vim /etc/php-fpm.d/www.conf
「user」と「group」を「nginx」に変更します。
user = nginx
group = nginx
'listen'構成を以下のようにsockファイルに変更します。
listen = /run/php-fpm/www.sock
以下のPHP環境変数のコメントを解除します。
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
最後の行でopcache構成のコメントを解除します。
php_value[opcache.file_cache] = /var/lib/php/opcache
保存して閉じます。
次に、PHPセッションとopcache用の新しいディレクトリを作成し、それらのディレクトリの所有者を「nginx」ユーザーとグループに変更します。
mkdir -p /var/lib/php/{session,opcache}
chown -R nginx:nginx /var/lib/php/{session,opcache}
これで、Nextcloudインストール用のPHP-FPM構成が完了しました。
PHP-FPMサービスを開始し、システムブートに追加します。
systemctl enable php-fpm
systemctl start php-fpm
次に、PHP-FPMソックスファイルとサービスステータスを確認します。
netstat -pl | grep php
systemctl status php-fpm
そして、以下のような結果が得られます。
その結果、PHP-FPMはsockファイル「/run/php-fpm/www.sock」で稼働しています。
このステップでは、MariaDBデータベースサーバーをインストールし、ルートパスワード認証を設定し、Nextcloud用の新しいデータベースとユーザーを作成します。
以下のdnfコマンドを使用してMariaDBデータベースをインストールします。
sudo dnf install mariadb mariadb-server
インストールが完了したら、MariaDBサービスを開始し、システムブートに追加します。
systemctl start mariadb
systemctl enable mariadb
そして、MariaDBサービスが稼働しています。
次に、以下の「mysql_secure_installation」コマンドを使用してルートパスワード認証を設定します。
mysql_secure_installation
ルートパスワードを入力し、残りの構成には「Y」と入力します。
Set a root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
そして、MariaDBルートパスワードが構成されました。
次に、以下のmysqlコマンドを使用してMySQLシェルにログインします。
mysql -u root -p
TYPE YOUR ROOT PASSWORD
次に、以下のクエリを使用して、新しいデータベース「nextcloud_db」を作成し、パスワード「nextcloudpassdb」で新しいユーザー「nextclouduser」を作成します。
create database nextcloud_db;
create user [email protected] identified by 'nextcloudpassdb';
grant all privileges on nextcloud_db.* to [email protected] identified by 'nextcloudpassdb';
flush privileges;
そして、Nextcloudインストール用のデータベースとユーザーを作成しました。
このステップでは、「certbot」を使用してSSLletsencryptを生成します。 SSL証明書はNextcloudアクセスを保護するために使用されます。
以下のdnfコマンドを使用して、EPELリポジトリからcertbotをインストールします。
sudo dnf install certbot
インストールが完了したら、以下のコマンドを使用してNextcloudドメイン名のSSL証明書を生成し、ドメイン名とメールアドレスを自分のものに変更してください。
certbot certonly --webroot --webroot-path /usr/share/nginx/html --agree-tos -m [email protected] -d cloud.hakase-labs.io
完了すると、生成されたすべてのSSL証明書は「/etc/letsencrypt/live/cloud.hakase-labs.io」ディレクトリに配置されます。
次のコマンドを使用して確認してください。
ls -lah /etc/letsencrypt/live/cloud.hakase-labs.io/
そして、certbotツールを使用してSSLletsencryptを生成しました。
このステップでは、Nextcloud17の最新バージョンをダウンロードします。
nextcloudソースコードをダウンロードする前に、zipパッケージをシステムにインストールしてください。
sudo dnf install unzip
次に、「/ var / www /」ディレクトリに移動し、以下のようにwgetコマンドを使用してNextcloudソースコードをダウンロードします。
cd /var/www/
wget https://download.nextcloud.com/server/releases/nextcloud-17.0.2.zip
以下のコマンドを使用してNextcloudソースコードを抽出します。
unzip nextcloud-17.0.2.zip
そして、「nextcloud」という新しいディレクトリが作成されます。
次に、Nextcloud用の新しい「データ」ディレクトリを作成します。 'data'ディレクトリは、ユーザーデータを保存するために使用されます。
mkdir -p /var/www/nextcloud/data/
その後、「nextcloud」ディレクトリの所有者を「nginx」ユーザーとグループに変更します。
sudo chown -R nginx:nginx /var/www/nextcloud
そして、最新のNextcloud17を「/var/www」ディレクトリにダウンロードしました。
Nextcloudソースコードをダウンロードした後、Nextcloud用にNginx仮想ホストをセットアップします。
'/etc/nginx/conf.d'ディレクトリに移動し、新しい構成'nextcloud.conf'を作成します。
cd /etc/nginx/conf.d/
vim nextcloud.conf
次に、ドメイン名とSSL証明書パスを独自のものに変更し、次の構成を貼り付けます。
upstream php-handler {
#server 127.0.0.1:9000;
server unix:/run/php-fpm/www.sock;
}
server {
listen 80;
listen [::]:80;
server_name cloud.hakase-labs.io;
# enforce https
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cloud.hakase-labs.io;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
# NOTE: some settings below might be redundant
ssl_certificate /etc/ssl/nginx/fullchain.pem;
ssl_certificate_key /etc/ssl/nginx/privkey.pem;
# 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=15768000; includeSubDomains; preload;" always;
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /var/www/nextcloud;
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;
# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
# set max upload size
client_max_body_size 512M;
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is built with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
location / {
rewrite ^ /index.php;
}
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\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
# Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
# Enable pretty urls
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# 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=15768000; includeSubDomains; preload;" always;
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
保存して閉じます。
その後、nginx構成をテストし、Nginxサービスを再起動します。そして、エラーがないことを確認してください。
nginx -t
systemctl restart nginx
これで、Nginxサービスがシステムに新しいHTTPSポートを開きます。次のコマンドを使用して、それを確認してください。
netstat -plntu
そして、以下のような結果が得られます。
その結果、NextcloudのNginx仮想ホスト構成を追加し、その上で安全なHTTPSを有効にしました。
このチュートリアルでは、「強制」モードでSELinuxを使用します。そして、Nextcloudインストール用にSELinuxをセットアップします。
以下のdnfコマンドを使用してSELinux管理ツールをインストールします。
sudo dnf install policycoreutils-python-utils
次に、サーバーでrootとして次のコマンドを実行します。
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/data(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/config(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/apps(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/assets(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/.htaccess'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/nextcloud/.user.ini'
restorecon -Rv '/var/www/nextcloud/'
そして、NextcloudのSELinux構成が完了しました。
次に、Webブラウザーを開き、アドレスバーにNextcloudドメイン名を入力します。
https://cloud.hakase-labs.io/
これで、次のようなNextcloudインストールページが表示されます。
管理者ユーザーとパスワードを入力し、データベースとして「MySQL / MariaDB」を選択して、上に作成したデータベースの詳細を入力します。
次に、[セットアップの完了]ボタンをクリックすると、インストールが開始されます。
インストールが完了すると、次のようなNextcloudダッシュボードが表示されます。
その結果、CentOS8サーバーにNginxWebサーバー、PHP-FPM 7.3、およびMariaDBデータベースを備えた最新のNextcloud17が正常にインストールされました。