17.5 NextCloud——基于 PostgreSQL

安装 nextcloud

为了方便安装,请使用 Ports 而非 pkg:

# cd /usr/ports/www/nextcloud/
# make config # 为了方便,仅配置 nextcloud 本体

本文选中 PGSQLSMBPCNTL;取消勾选 MYSQL

nextcloud Port

编译安装:

# make BATCH=yes install clean

安装配置 PostgreSQL

安装(请留意上面 ports 默认安装的 postgresql-client 版本,尽量一致)

注意

若使用 pkg 安装,请另行安装 databases/php83-pdo_pgsql,php 版本须同

# pkg install postgresql16-server

或者:

# cd /usr/ports/databases/postgresql16-server/ 
# make install clean

配置:

root@ykla:~ # service postgresql enable
postgresql enabled in /etc/rc.conf

初始化数据库

root@ykla:~ # service postgresql initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with this locale configuration:
  provider:    libc
  LC_COLLATE:  C
  LC_CTYPE:    C.UTF-8
  LC_MESSAGES: C.UTF-8
  LC_MONETARY: C.UTF-8
  LC_NUMERIC:  C.UTF-8
  LC_TIME:     C.UTF-8
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data16 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/local/bin/pg_ctl -D /var/db/postgres/data16 -l logfile start
root@ykla:/usr/ports/www/nextcloud #  su - postgres #切换到数据库用户
$ /usr/local/bin/pg_ctl -D /var/db/postgres/data16/ -l logfile start # 初始化
waiting for server to start.... done
server started
$ psql -Upostgres # 进入命令模式
psql (16.7)
Type "help" for help.

postgres=# create user nextcloud; # 创建所需用户
CREATE ROLE
postgres=# \password nextcloud # 创建用户 nextcloud 密码,注意斜杠要输入:\ 
Enter new password for user "nextcloud": # 此处输入密码,密码不会显示到屏幕上,也不是 *,就是空的,下同
Enter it again: # 再次重复输入上面密码
postgres=# create database nextcloud owner=nextcloud; # 创建所需数据库的属主
CREATE DATABASE
postgres-# \q # 退出,注意斜杠要输入:\ 

技巧

远程访问数据库服务器请自行配置 /var/db/postgres/data16/pg_hba.conf

示例(IP 段 10.0.50.5/32 照抄不管用):

host    nextcloud       nextcloud       10.0.50.5/32               scram-sha-256

安装 mod_php

注意版本可以通过 php -v 命令判断,必须一致:

root@ykla:~ # php -v
PHP 8.3.17 (cli) (built: Feb 15 2025 01:11:28) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.17, Copyright (c), by Zend Technologies
# pkg install mod_php83
# service php_fpm enable
# service php_fpm start

基于 Apache

# pkg install apache24

或者

# cd /usr/ports/www/apache24/ 
# make install clean

配置服务:

# service apache24 enable

查看 Apache 配置方法

root@ykla:/usr/ports/www/nextcloud # pkg info -D mod_php83
root@ykla:~ # pkg info -D mod_php83
mod_php83-8.4.4_1:
On install:
******************************************************************************

Consider switching to php-fpm and mod_fast_cgi as per Apache httpd project
recommendation. See https://cwiki.apache.org/confluence/display/HTTPD/PHP-FPM
建议根据 Apache httpd 项目的推荐,切换到 php-fpm 和 mod_fast_cgi。详情请见 https://cwiki.apache.org/confluence/display/HTTPD/PHP-FPM

******************************************************************************

If you are building PHP-based ports in poudriere(8) or Synth with ZTS enabled,
add WITH_MPM=event to /etc/make.conf to prevent build failures.
如果你在 poudriere(8) 或 Synth 中构建启用了 ZTS 的 PHP 基础端口,请将 WITH_MPM=event 添加到 /etc/make.conf,以防止构建失败。

******************************************************************************

Make sure index.php is part of your DirectoryIndex.
确保 index.php 是 DirectoryIndex 的一部分。

You should add the following to your Apache configuration file:
你应该将以下内容添加到你的 Apache 配置文件中:

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

******************************************************************************
root@ykla:~ # pkg info -D nextcloud-php83
nextcloud-php83-30.0.6:
On install:
 /!\ The FreeBSD package REQUIRES the apps_paths configuration as    /!\
 /!\ seen in config/config.sample.php to function                    /!\
 /!\ FreeBSD 包需要配置 apps_paths,如 config/config.sample.php 中所示才能正常工作 /!\

Please note that everything has been installed in /usr/local/www/nextcloud.
请注意,所有文件已安装在 /usr/local/www/nextcloud 中。

You will probably want to add an alias to your httpd.conf file,
something like this:
你可能需要在 httpd.conf 文件中添加一个别名,类似如下:

    	Alias /nextcloud /usr/local/www/nextcloud
	AcceptPathInfo On
	<Directory /usr/local/www/nextcloud>
	    AllowOverride All
	    Require all granted
	</Directory>

And restart Apache. Nextcloud will start the bundled installer on first
access. Once the bundled installer finishes, further configuration can
be done via 'Settings', 'Administration'. Additional configuration
options are available in
然后重启 Apache。Nextcloud 会在首次访问时启动捆绑的安装程序。安装程序完成后,可以通过 'Settings' 和 'Administration' 进行进一步配置。更多配置选项可以在以下位置找到:

	/usr/local/www/nextcloud/config/config.php

You can find annotated configuration options in config.documented.php
in the same directory. Nextcloud's configuration documentation is at
你可以在同一目录下的 config.documented.php 中找到带注释的配置选项。Nextcloud 的配置文档请参考:

	https://docs.nextcloud.com/server/stable/admin_manual/configuration_server

The caching options require additional Nextcloud configuration.
缓存选项需要额外的 Nextcloud 配置。

On upgrade:
After a version migration you should upgrade your nextcloud instance
using command line:
升级后,你应该使用命令行升级你的 nextcloud 实例:

  occ upgrade

Merge any changes to /usr/local/www/nextcloud/.htaccess.dist into .htaccess (above the
'#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####' divider if it exists)
and update the dynamic part of the file using the commandline:
将 /usr/local/www/nextcloud/.htaccess.dist 中的任何更改合并到 .htaccess 文件中(如果存在的话,请合并到 '#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####' 分隔符上方),并使用命令行更新文件的动态部分:

  occ maintenance:update:htaccess

As of Nextcloud 27.1.0 the recommended PHP version is 8.2.
Nextcloud 27.1.0,推荐使用 PHP 8.2 版本。

编辑 /usr/local/etc/apache24/httpd.conf,加入:

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

Alias /nextcloud /usr/local/www/nextcloud
    AcceptPathInfo On
<Directory /usr/local/www/nextcloud>
    AllowOverride All
    Require all granted
</Directory>

启动 Apache:

# service apache24 start

启动

http://ip/nextcloud 即可。请把 ip 替换成你的局域网 ip。

nextcloud FreeBSD 安装界面

请输入你需要的登录账户和密码。其他照抄即可。

nextcloud FreeBSD 安装中

安装完成会重定向到插件推荐:不必理会,重新定位到 "http://ip/nextcloud" 即可正常使用之。

nextcloud FreeBSD 安装后
nextcloud FreeBSD 开始界面

在 nextcloud 中挂载 samba 共享

安装模块 php83-pecl-smbclient

在 nextcloud 服务器端:

# pkg install php83-pecl-smbclient

或者

# cd /usr/ports/net/pecl-smbclient/ 
# make install clean

重启 apache:

# service apache24 restart

设置 samba 共享

找到“应用”

nextcloud_smb_1

找到外部存储支持,并启用之(默认已禁用)

nextcloud_smb_2

进入管理设置:

nextcloud_smb_3

找到管理中的外部存储(不是“个人”里面的外部存储)

nextcloud_smb_4

查看所有文件,samba 已启用:

nextcloud_smb_5

备注

其他常用插件,可以用 pkg search -x nextcloud | grep php82 查找,pkg 安装。

注意

之前有些版本在初始化 nextcloud 时,会有权限问题,请你检查 /usr/local/www/nextcloudconfig 目录及其下文件的访问权限,看运行 apache 的用户是否可读写之。

参考文献

最后更新于