如何在 Debian 11 上安装 Nextcloud

在本教程中,我们将向您展示如何在 Debian 11 上安装 Nextcloud。对于那些不知道的人,Nextcloud 是一个 Web 套件,它通过网络提供云存储,是其 ownCloud 的一个分支。 它允许您创建自托管服务,例如 Dropbox 或 Google Drive。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,最重要的是,您将站点托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 到获得 root 权限的命令。 我将向您展示在 Debian 11 (Bullseye) 上逐步安装 Nextcloud。

在 Debian 11 Bullseye 上安装 Nextcloud

步骤 1. 在我们安装任何软件之前,请务必通过运行以下命令来确保您的系统是最新的 apt 终端中的命令:

sudo apt update sudo apt upgrade

步骤 2. 安装 LAMP 堆栈。

需要 Debian 11 LAMP 服务器。 如果您没有安装 LAMP,请阅读我们之前的教程,在 Debian 11 上安装 LAMP Stack。

步骤 3. 在 Debian 11 上安装 Nextcloud。

现在我们从官方页面下载最新版本的Nextcloud:

cd /var/www/ curl -o nextcloud.zip https://download.nextcloud.com/server/releases/nextcloud-22.1.1.zip

接下来,解压缩 Nextcloud zip 文件:

unzip nextcloud-22.1.0.zip

我们需要更改一些文件夹的权限:

chown -R www-data:www-data nextcloud

步骤 4. 配置 MariaDB。

默认情况下,MariaDB 未加固。 您可以使用以下方法保护 MariaDB mysql_secure_installation 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录,以及删除测试数据库和访问安全 MariaDB 的权限。

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y

接下来,我们需要登录到 MariaDB 控制台并为 Nextcloud 创建一个数据库。 运行以下命令:

mysql -u root -p

这将提示您输入密码,因此请输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 Nextcloud 安装创建一个数据库:

MariaDB [(none)]> CREATE DATABASE nextcloud; MariaDB [(none)]> CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'your-strong-password'; MariaDB [(none)]> GRANT ALL ON nextcloud.* TO 'nextclouduser'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;

步骤 5. 设置 SSL Letsencrypt。

首先,我们安装 certbot 工具来为您的系统生成 SSL Letsencrypt:

sudo apt install certbot

然后,使用以下命令为 Letsencrypt 授权创建一个新目录:

mkdir -p /var/lib/letsencrypt/.well-known chgrp www-data /var/lib/letsencrypt chmod g+s /var/lib/letsencrypt

接下来,将目录更改为“/etc/apache2/conf-available/”并创建一个新的配置“well-known.conf” 使用您最喜欢的文本编辑器:

cd /etc/apache2/conf-available/ nano well-known.conf

添加以下文件:

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" <Directory "/var/lib/letsencrypt/">     AllowOverride None     Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec     Require method GET POST OPTIONS </Directory>

之后,创建 ‘ 的符号链接well-known.conf‘文件到目录’conf-enabled‘ 使用下面的 ‘ln’ 命令:

ln -s /etc/apache2/conf-available/well-known.conf /etc/apache2/conf-enabled/

最后,验证 Apache 配置并重启 Apache 服务:

apachectl configtest sudo systemctl restart apache2

步骤 6. 配置 Apache.

现在我们创建一个新的 Apache Nextcloud 的虚拟主机配置:

cd /etc/apache2/sites-available/ nano nextcloud.conf

添加以下行:

<VirtualHost *:80>     ServerName files.your-domain.com     ServerAlias www.files.your-domain.com      # auto redirect HTTP to HTTPS     Redirect permanent / https://files.your-domain.com/ </VirtualHost>  <VirtualHost *:443>     ServerName files.your-domain.com     ServerAlias www.files.your-domain.com        DocumentRoot /var/www/nextcloud/      Protocols h2 http/1.1      # auto redirect www to non-www     <If "%{HTTP_HOST} == 'www.files.your-domain.com'">         Redirect permanent / https://files.your-domain.com/     </If>      # log files     ErrorLog /var/log/apache2/files.your-domain.com-error.log     CustomLog /var/log/apache2/files.your-domain.com-access.log combined      SSLEngine On     SSLCertificateFile /etc/letsencrypt/live/files.your-domain.com/fullchain.pem     SSLCertificateKeyFile /etc/letsencrypt/live/files.your-domain.com/privkey.pem      # HSTS     <IfModule mod_headers.c>         Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"     </IfModule>      <Directory /var/www/nextcloud/>         Options +FollowSymlinks         AllowOverride All          <IfModule mod_dav.c>             Dav off         </IfModule>          SetEnv HOME /var/www/nextcloud         SetEnv HTTP_HOME /var/www/nextcloud     </Directory> </VirtualHost>

现在,我们可以重新启动 Apache 网络服务器,以便进行更改:

sudo a2enmod rewrite sudo a2ensite nextcloud.conf sudo systemctl restart apache2

步骤 7. 访问 Nextcloud Web 界面。

成功安装后,现在打开您最喜欢的浏览器并导航到 https://files.your-domain.com/ 并完成所需的步骤以完成安装。 如果您使用防火墙,请打开端口 80 以启用对控制面板的访问。

恭喜! 您已成功安装 Nextcloud。 感谢您使用本教程在 Debian 11 Bullseye 上安装最新版本的 Nextcloud。 如需更多帮助或有用信息,我们建议您查看 Nextcloud 官方网站.