Closed9

Nextcloudを構築する(2023年)

ruisruis

今回の構成は、前回と変更して
 ・Nextcloud本体
 ・データベース
を分離する構成でやる。

ruisruis

まずは、データベースの構築から。
下記の記事を参考に、Dockerをインストール。
https://zenn.dev/seiwell/articles/7ca8a8c4bda10c

ruisruis

インストール後、適当なディレクトリを作成。
今回は、nextcloud-dbとした。
次に、docker-compose.ymlを作成。

version : "3"
services:
  db:
    image: mariadb
    restart: always
    ports:
      - 3306:3306
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=<root用パスワード>
      - MYSQL_PASSWORD=<nextcloudユーザーのパスワード>
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

volumes:
  db:
ruisruis

docker-compose.ymlを書き込んだら、

docker compose up -d

で起動する

ruisruis

次に、Nextcloud本体の構築をする。
パッケージのインストール

sudo apt install apache2 php php-xml php-cgi php-cli php-mysql php-mbstring php-gd php-curl php-zip php-imagick php-gmp php-intl php-bcmath ffmpeg zip -y

PHPの設定

sudo nano /etc/php/8.1/apache2/php.ini

変更点

;memory_limit = 128M
memory_limit = 1024M

;post_max_size = 2M
post_max_size = 102400M

;upload_max_filesize = 2M
upload_max_filesize = 102400M

Apacheのドキュメントルートを変更

/etc/apache2/sites-enabled/000-default.conf

変更点:

  GNU nano 6.2                                                                                   000-default.conf *                                                                                           
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
-        DocumentRoot /var/www/html/
+       DocumentRoot /var/www/html/nextcloud

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Apacheの再起動

sudo systemctl restart apache2
ruisruis

自分の場合は、外付けHDDをデータフォルダーとするので、その設定
外付けHDDのマウントまで

sudo mkdir -p /mnt/DISK
sudo fdisk -l
Disk /dev/sdb: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: External HDD    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6E77D684-77EF-4F94-A0F6-557082E0EED9

Device     Start        End    Sectors  Size Type
/dev/sdb1   2048 7814035455 7814033408  3.6T Linux filesystem

マウント

sudo mount /dev/sdb1 /mnt/DISK
sudo blkid | grep /dev/sdb1

自動マウントの設定

sudo nano /etc/fstab
ruisruis

エラー修正
・「PHP configuration option output_buffering must be disabled」参考リンク

sudo nano /etc/php/8.1/apache2/php.ini
- output_buffering = 4096
+ output_buffering = Off

・「ご使用のシステムには、デフォルトの電話地域が設定されていません。これは、国コードなしでプロファイル設定の電話番号を検証するために必要です。国コードなしで番号を許可するには、地域のそれぞれの ISO3166-1コード↗とともに "default_phone_region" を設定ファイルに追加してください。」参考リンク

sudo nano /var/www/html/nextcloud/config/config.php

追記

'default_phone_region' => 'JP',

・「メモリーキャッシュが構成されていません。パフォーマンスを向上させるために、可能な場合はmemcacheを構成してください。詳細については、ドキュメント↗をご覧ください。」参考リンク

sudo apt install php-apcu
sudo nano /var/www/html/nextcloud/config/config.php

追記

'memcache.local' => '\OC\Memcache\APCu',

・「このインスタンスのphp-imagickモジュールはSVGをサポートしていません。互換性の向上のために、インストールすることをお勧めします。」参考リンク

sudo apt install libmagickcore-6.q16-6-extra
ruisruis

バックグラウンドジョブをAjaxからCronに変更する

sudo crontab -u www-data -e

追記

*/5 * * * * /usr/bin/php -f /var/www/html/nextcloud/cron.php
sudo nano /etc/php/8.1/cli/php.ini

末尾に追記

apc.enable_cli=1
このスクラップは2023/08/06にクローズされました