自建Nextcloud私有云盘
安装
从Nextcloud官方网站下载server的安装包,复制到/var/www
目录解压。
详细安装过程参考官方文档
1、按照官方文档安装完善php模块
必须要安装的模块
PHP (see System requirements for a list of supported versions)
PHP module ctype
PHP module curl
PHP module dom
PHP module fileinfo (included with PHP)
PHP module filter (only on Mageia and FreeBSD)
PHP module GD
PHP module hash (only on FreeBSD)
PHP module JSON (included with PHP >= 8.0)
PHP module libxml (Linux package libxml2 must be >=2.7.0)
PHP module mbstring
PHP module openssl (included with PHP >= 8.0)
PHP module posix
PHP module session
PHP module SimpleXML
PHP module XMLReader
PHP module XMLWriter
PHP module zip
PHP module zlib
选择合适的数据库模块:
PHP module pdo_sqlite (>= 3, usually not recommended for performance reasons)
PHP module pdo_mysql (MySQL/MariaDB)
PHP module pdo_pgsql (PostgreSQL)
推荐安装的模块:
PHP module bz2 (recommended, required for extraction of apps)
PHP module intl (increases language translation performance and fixes sorting of non-ASCII characters)
2、Apache配置文件
新增配置文件vim /etc/apache2/sites-available/nextcloud.conf
,复制以下内容:
1 | <VirtualHost *:80> |
保存,然后运行:
1 | a2ensite nextcloud.conf |
启用必要的Apache模块:
1 | a2enmod rewrite |
If you’re running mod_fcgi instead of the standard mod_php also enable:
1 | a2enmod setenvif |
最后重启Apache:
1 | service apache2 restart |
现在就可以访问http://your.server.com
安装Nextcloud。
Redis缓存配置
修改配置文件nextcloud/config/config.php
:
Small/Private home server
Only use APCu:
1 | 'memcache.local' => '\OC\Memcache\APCu', |
Organizations with single-server
Use Redis for everything except local memcache:
1 | 'memcache.local' => '\OC\Memcache\APCu', |
Organizations with clustered setups
Use APCu for local cache and either Redis cluster …:
1 | 'memcache.local' => '\OC\Memcache\APCu', |
APCu is disabled by default on CLI which could cause issues with nextcloud’s cron jobs. Please make sure you set the
apc.enable_cli
to1
on yourphp.ini
config file or append--define apc.enable_cli=1
to the cron job call.
1 | vim /etc/php/8.1/cli/php.ini |
在末尾添加apc.enable_cli=1
,否则当你运行occ命令的时候也会提示你APCu不可用。
OCC命令的使用
直接运行occ
命令,不带任何选项,就会列出occ命令的所有可用的选项和用法:
1 | sudo -u www-data php8.1 /var/www/nextcloud/occ |
返回信息:
1 | Nextcloud 24.0.12 |
扫描所有用户文件更新:
1 | sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan --all |
扫描特定用户文件更新:
1 | sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan username |
扫描特定目录文件更新:
1 | sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan --path=/path/to/scan |
后台服务优化
后台服务有三种方式:AJAX,Webcron,Cron
systemd
If systemd is installed on the system, a systemd timer could be an alternative to a cronjob.
This approach requires two files: nextcloudcron.service
and nextcloudcron.timer
. Create these two files in /etc/systemd/system/
.
nextcloudcron.service should look like this:
1 | [Unit] |
Replace the user www-data
with the user of your http server and /var/www/nextcloud/cron.php
with the location of cron.php
in your nextcloud directory.
The KillMode=process
setting is necessary for external programs that are started by the cron job to keep running after the cron job has finished.
Note that the .service unit file does not need an [Install]
section. Please check your setup because we recommended it in earlier versions of this admin manual.
nextcloudcron.timer should look like this:
1 | [Unit] |
The important parts in the timer-unit are OnBootSec
and OnUnitActiveSec
. OnBootSec
will start the timer 5 minutes after boot, otherwise you would have to start it manually after every boot. OnUnitActiveSec
will set a 5 minute timer after the service-unit was last activated.
Now all that is left is to start and enable the timer by running this command:
1 | systemctl enable --now nextcloudcron.timer |
When the option --now
is used with enable
, the respective unit will also be started.