跳转至

# Nextcloud 手动安装流程#

Debian 上使用 nginx 与 postgresql 的安装记录并不多,基本上按照这篇教程来进行: Nextcloud 23 Installation on Debian

PHP 安装#

官方 Linux 安装教程,主要看下里面需要的 php 拓展包:https://docs.nextcloud.com/server/latest/admin_manual/installation/index.html ,因为官方推荐用 php8.0 而 Debian10 系统默认最新的版本似乎是 7.3,所以要手动去拉取新版本 php-fpm(注意是 fpm,因为我们用 nginx),过程如下( https://www.linuxtechi.com/install-php-8-on-debian-10/ ):

Step 1) Install updates with apt command

sudo apt update
sudo apt upgrade -y

Step 2) Enable PHP 8 Repository (SURY PPA)

sudo apt install -y lsb-release apt-transport-https ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Step 3) Install PHP 8 using apt command

sudo apt install php8.0-fpm -y
sudo apt install -y php8.0-{sql,cli,common,snmp,ldap,curl,mbstring,zip} -y 
# 整合安装 package
php -m 
# To list all the loaded PHP modules, run beneath php command

测试https://emanuelpina.pt/php-installation-on-debian/#install-php

sudo nano /etc/nginx/sites-available/default

And edit the server block to add the following code, just bellow the server_name. Like this:

server {
    ###

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
    }

    ###
}

Test to make sure that there are no syntax errors in our Nginx files:

sudo nginx -t

If there aren’t any issues, restart Nginx to enable the changes:

sudo systemctl reload nginx

Now let’s create a test PHP file in the website root folder:

sudo nano /var/www/html/info.php

Add the following content to the file, which is a valid PHP code that generates a page containing information about the server:

<?php
phpinfo();

Now visiting the page https://<ip-address>/info.php on a browser we should see a page generated by PHP containing structured information about our server.

If you see this page then Nginx is successfully communicating with PHP!

At the end of this test, don’t forget to remove the PHP file we created:

sudo rm /var/www/html/info.php

PHP 包安装#

之后正常安装 Nextcloud,我安装的版本为 24.0.1,到了安装 php package 时,我目前已经安装的有这些:

  • php8.0-curl
  • php8.0-dom
  • php8.0-gd
  • php8.0-mbstring
  • php8.0-zip

(上面的是必须安装的,下面的可选)

  • php8.0-bz2
  • php8.0-intl
  • php8.0-gmp
  • php8.0-imap
  • php8.0-bcmath
  • php8.0-ldap
  • php8.0-pgsql
  • php8.0-redis
  • php8.0-imagick
# 实际安装的所有 php 相关 packages
php-common/buster,now 2:92+0~20220117.43+debian10~1.gbpe0d14e all [installed,automatic]
php8.0-apcu/buster,now 5.1.21+4.0.11-7+0~20220117.31+debian10~1.gbp9a887a amd64 [installed]
php8.0-bcmath/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-bz2/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-cli/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed,automatic]
php8.0-common/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-curl/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-fpm/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-gd/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-gmp/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-igbinary/buster,now 3.2.7+2.0.8-1+0~20220421.34+debian10~1.gbp53e1f5 amd64 [installed,automatic]
php8.0-imagick/buster,now 3.6.0-4+0~20220117.35+debian10~1.gbp149f82 amd64 [installed]
php8.0-imap/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-intl/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-ldap/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-mbstring/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-opcache/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed,automatic]
php8.0-pgsql/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-readline/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed,automatic]
php8.0-redis/buster,now 5.3.7+4.3.0-1+0~20220330.42+debian10~1.gbp6fe8b7 amd64 [installed]
php8.0-xml/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]
php8.0-zip/buster,now 1:8.0.20-1+0~20220610.34+debian10~1.gbp11fdd0 amd64 [installed]

Configure PHP#

sudo nano /etc/php/8.0/fpm/php.ini

修改了以下内容

post_max_size = 16G
upload_max_filesize = 16G
# 单个大文件上传上限

[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=1
opcache.save_comments=1

Another thing is that as we’re using php-fpm, system environment variables like PATH, TMP or others are not automatically populated. A PHP call like getenv('PATH'); can therefore return an empty result. So we need to manually configure the environment variables in www.conf. To edit this file run:

sudo nano /etc/php/7.4/fpm/pool.d/www.conf

Just uncomment the ones that refer to PATH and TMP, like this: (根据)

env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp

Run printenv PATH to confirm your paths, for example:

$ printenv PATH
/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:
/sbin:/bin:/

If any of your system environment variables are not present in the file then you must add them.(你好像没有添加)

数据库与 Nginx#

https://emanuelpina.pt/nextcloud-23-installation-on-debian/#create-postgresql-user-and-database

记得一定不要省略密码,后面必备。

后台 cronb#

https://docs.nextcloud.com/server/24/admin_manual/configuration_server/background_jobs_configuration.html

systemctl enable --now nextcloudcron.timer

待做:#

occ config:app:set previewgenerator squareSizes --value="32 256"
occ config:app:set previewgenerator widthSizes  --value="256 384"
occ config:app:set previewgenerator heightSizes --value="256"
occ config:system:set preview_max_x --value 2048
occ config:system:set preview_max_y --value 2048
occ config:system:set jpeg_quality --value 60
occ config:app:set preview jpeg_quality --value="60"

所有命令前都要加上 sudo -u www-data php,在 /var/www/nextcloud 下进行。