エックスサーバーにインストールした Nextcloud を、Webブラウザではなくコマンドライン(CLI)経由で安全にバージョンアップする手順を紹介します。
今回は「Nextcloud 31.0.4 → 31.0.5」へのアップデートを例に、実行したコマンドとその出力結果をすべて表示しています。エックスサーバーでも再現可能な実例です。
使用環境
- PHP:8.2.22(パス:
/opt/php-8.2.22/bin/php
) - MySQL(MariaDB):10.5.x
- サーバー:エックスサーバー
- Nextcloud:31.0.4 → 31.0.5
1. メンテナンスモードを有効にする
/opt/php-8.2.22/bin/php ./occ maintenance:mode --on
実行結果:
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php
Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini.
Maintenance mode enabled
2. アップデーターの実行
/opt/php-8.2.22/bin/php ./updater/updater.phar
実行結果(全文):
Nextcloud Updater - version: v30.0.2rc1-9-ge6d305f
Current version is 31.0.4.
Update to Nextcloud 31.0.5 available. (channel: "stable")
Following file will be downloaded automatically: https://download.nextcloud.com/server/releases/nextcloud-31.0.5.zip
Open changelog ↗
Steps that will be executed:
[ ] Check for expected files
[ ] Check for write permissions
[ ] Create backup
[ ] Downloading
[ ] Verify integrity
[ ] Extracting
[ ] Enable maintenance mode
[ ] Replace entry points
[ ] Delete old files
[ ] Move new files in place
[ ] Done
Start update? [y/N] y
Info: Gracefully stopping the updater via Ctrl-C is not possible - PCNTL extension is not loaded.
[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[✔] Delete old files
[✔] Move new files in place
[✔] Done
Update of code successful.
Should the "occ upgrade" command be executed? [Y/n] y
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php
Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini.
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Repair step: Repair MySQL collation
Repair info: All tables already have the correct collation -> nothing to do
Repair step: Copy data from accounts table when migrating from ownCloud
Repair step: Drop account terms table when migrating from ownCloud
Updating database schema
Updated database
Repair step: Repair MySQL collation
Repair info: All tables already have the correct collation -> nothing to do
Repair step: Clean tags and favorites
Repair info: 0 tags of deleted users have been removed.
Repair info: 0 tags for delete files have been removed.
Repair info: 0 tag entries for deleted tags have been removed.
Repair info: 0 tags with no entries have been removed.
Repair step: Repair invalid shares
Repair step: Move .step file of updater to backup location
Repair info: .step file exists
Repair info: .step file moved to .step-previous-update
Repair step: Add move avatar background job
Repair info: Add background job
Repair step: Add preview cleanup background jobs
Repair step: Migrate oauth2_clients table to nextcloud schema
Repair info: Update the oauth2_access_tokens table schema.
Repair info: Update the oauth2_clients table schema.
Repair info: Delete clients (and their related access tokens) with the redirect_uri starting with oc:// or ending with *
Repair step: Repair language codes
Repair step: Add log rotate job
Repair step: Clear frontend caches
Repair info: Image cache cleared
Repair info: JS cache cleared
Repair step: Clear every generated avatar
Repair step: Add preview background cleanup job
Repair step: Queue a one-time job to cleanup old backups of the updater
Repair step: Cleanup invalid photocache files for carddav
Repair step: Add background job to cleanup login flow v2 tokens
Repair step: Remove potentially over exposing share links
Repair info: No need to remove link shares.
Repair step: Clear access cache of projects
Repair step: Reset generated avatar flag
Repair step: Keep legacy encryption enabled
Repair step: Check encryption key format
Repair step: Remove old dashboard app config data
Repair step: Add job to cleanup the bruteforce entries
Repair step: Queue a one-time job to check for user uploaded certificates
Repair step: Repair DAV shares
Repair step: Add background job to set the lookup server share state for users
Repair step: Add token cleanup job
Repair step: Clean up abandoned apps
Repair step: Add possibly missing system config
Repair step: Add AI tasks cleanup jobs
Repair step: Queue a job to generate metadata
Repair step: migrate lazy config values
Repair step: Cache logo dimension to fix size in emails on Outlook
Repair info: Theming is not used to provide a logo
Repair step: Remove legacy ".ocdata" file
Repair step: Add cleanup-deleted-users background job
Repair step: Validate account properties and store phone numbers in a known format for search
Repair info: Queued background to validate account properties.
Starting code integrity check...
Finished code integrity check
Update successful
Maintenance mode is kept active
Resetting log level
3. メンテナンスモードを終了する
/opt/php-8.2.22/bin/php ./occ maintenance:mode --off
実行結果:
The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php
Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini.
Maintenance mode disabled
4. .htaccess の修正(500エラー対策)
アップデート後、Nextcloud が自動生成する .htaccess
により、以前削除した ModPagespeed
に関する記述が復活し、500エラーが再発する場合があります。
対応方法
Nextcloudのルートにある .htaccess
を開き、以下の記述を削除またはコメントアウトしてください。
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
修正後の例(コメントアウト):
# <IfModule pagespeed_module>
# ModPagespeed Off
# </IfModule>
補足:操作のまとめ
操作 | コマンド |
---|---|
メンテナンスモード ON | /opt/php-8.2.22/bin/php ./occ maintenance:mode --on |
アップデーター実行 | /opt/php-8.2.22/bin/php ./updater/updater.phar |
データベースアップグレード | occ upgrade をプロンプトで y |
メンテナンスモード OFF | /opt/php-8.2.22/bin/php ./occ maintenance:mode --off |
.htaccess 修正 | ModPagespeed の行を削除またはコメントアウト |
おわりに
Nextcloud を CLI 経由で安全に運用・更新することで、Webインターフェースよりも効率的でエラーの少ないメンテナンスが可能です。エックスサーバー上でもこのように CLI 操作で十分対応できますので、参考になれば幸いです。
コメント