在当今的数字时代,数据是我们个人和职业生活的核心。对安全、可访问和可定制的云存储解决方案的需求从未如此强烈。Nextcloud 是一个功能强大的开源文件共享平台,提供了完美的解决方案。
在 Debian 上安装 Nextcloud 12 Bookworm
第 1 步。在安装任何软件之前,请务必通过在终端中运行以下命令来确保您的系统是最新的:apt
<span class="pln">sudo apt update sudo apt upgrade</span>
此命令更新软件包列表,并将已安装的软件包升级到最新版本。
第 2 步。安装 Apache Web Server。
Apache 是一个流行的 Web 服务器,我们将使用它来托管 Nextcloud。使用以下命令安装 Apache:
<span class="pln">sudo apt install apache2</span>
安装后,启动 Apache 并使其在启动时启动:
<span class="pln">sudo systemctl start apache2 sudo systemctl enable apache2</span>
如果您使用的是防火墙,请不要忘记允许 HTTP 和 HTTPS 流量:
<span class="pln">ufw allow </span><span class="lit">80</span><span class="pun">,</span><span class="lit">443</span><span class="pun">/</span><span class="pln">tcp ufw reload</span>
第 3 步。安装 MySQL 数据库服务器。
Nextcloud 需要一个数据库来存储其配置和数据。为此,我们将使用 MySQL。现在安装 MySQL Server:
<span class="pln">sudo apt install mysql</span><span class="pun">-</span><span class="pln">server</span>
安装后,运行 MySQL 安全安装脚本:
<span class="pln">mysql_secure_installation</span>
安装后,运行 MySQL 安全安装脚本:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
执行以下 SQL 命令,将 、 和替换为首选值:[your_db_name]
[your_db_user]
[your_db_password]
<span class="pln">CREATE DATABASE </span><span class="pun">[</span><span class="pln">your_db_name</span><span class="pun">];</span><span class="pln"> CREATE USER </span><span class="str">'[your_db_user]'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'[your_db_password]'</span><span class="pun">;</span><span class="pln"> GRANT ALL PRIVILEGES ON </span><span class="pun">[</span><span class="pln">your_db_name</span><span class="pun">].*</span><span class="pln"> TO </span><span class="str">'[your_db_user]'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span><span class="pln"> EXIT</span><span class="pun">;</span>
第 4 步。安装 PHP 和必需的模块。
Nextcloud依靠PHP和几个PHP模块才能正常运行。现在安装 PHP 和所需的模块:
<span class="pln">sudo apt install php libapache2</span><span class="pun">-</span><span class="pln">mod</span><span class="pun">-</span><span class="pln">php php</span><span class="pun">-</span><span class="pln">mysql php</span><span class="pun">-</span><span class="pln">zip php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">json php</span><span class="pun">-</span><span class="pln">curl php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">imagick php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">pear php</span><span class="pun">-</span><span class="pln">redis php</span><span class="pun">-</span><span class="pln">apcu</span>
然后,打开 PHP 配置文件:
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">/</span><span class="lit">8.x</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>
查找并调整以下设置:
<span class="pln">memory_limit </span><span class="pun">=</span> <span class="lit">512M</span><span class="pln"> upload_max_filesize </span><span class="pun">=</span> <span class="lit">1G</span><span class="pln"> post_max_size </span><span class="pun">=</span> <span class="lit">1G</span><span class="pln"> max_execution_time </span><span class="pun">=</span> <span class="lit">360</span><span class="pln"> date</span><span class="pun">.</span><span class="pln">timezone </span><span class="pun">=</span> <span class="pun">[</span><span class="pln">your_timezone</span><span class="pun">]</span>
保存并退出文件。重新启动 Apache 以应用更改:
<span class="pln">systemctl restart apache2</span>
第 5 步。在 Debian 上安装 Nextcloud 12
现在,是时候让Nextcloud栩栩如生了。从官方网站下载Nextcloud的最新稳定版本:
<span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">nextcloud cd </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">nextcloud wget https</span><span class="pun">:</span><span class="com">//download.nextcloud.com/server/releases/latest.tar.bz2</span>
解压存档:
<span class="pln">tar xvf latest</span><span class="pun">.</span><span class="pln">tar</span><span class="pun">.</span><span class="pln">bz2</span>
创建一个目录来存储Nextcloud数据:
<span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">nextcloud</span><span class="pun">/</span><span class="pln">data</span>
使 Web 服务器成为数据目录的所有者:
<span class="pln">chown </span><span class="pun">-</span><span class="pln">R www</span><span class="pun">-</span><span class="pln">data</span><span class="pun">:</span><span class="pln">www</span><span class="pun">-</span><span class="pln">data </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">nextcloud</span><span class="pun">/</span>
第 6 步。设置 Apache 虚拟主机。
我们需要为 Nextcloud 创建一个虚拟主机配置文件:
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">nextcloud</span><span class="pun">.</span><span class="pln">conf</span>
添加以下内容,替换为您的域名或 IP 地址:[your_domain]
<span class="tag"><VirtualHost</span><span class="pln"> *:80</span><span class="tag">></span><span class="pln"> ServerAdmin admin@[your_domain] DocumentRoot /var/www/html/nextcloud ServerName [your_domain] ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </span><span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">nextcloud</span><span class="tag">/></span><span class="pln"> Require all granted AllowOverride All Options FollowSymLinks MultiViews SetEnv HOME /var/www/html/nextcloud SetEnv HTTP_HOME /var/www/html/nextcloud </span><span class="tag"></Directory></span> <span class="tag"></VirtualHost></span>
Enable the virtual host you just created:
<span class="pln">a2ensite nextcloud</span><span class="pun">.</span><span class="pln">conf</span>
接下来,修改默认的 Apache 配置以确保与 Nextcloud 的兼容性:
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache2</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">nextcloud</span><span class="pun">.</span><span class="pln">conf</span>
添加以下行:
<span class="tag"><Directory</span> <span class="pun">/</span><span class="atn">var</span><span class="pun">/</span><span class="atn">www</span><span class="pun">/</span><span class="atn">html</span><span class="pun">/</span><span class="atn">nextcloud</span><span class="tag">/></span><span class="pln"> Require all granted AllowOverride All Options FollowSymLinks MultiViews SetEnv HOME /var/www/html/nextcloud SetEnv HTTP_HOME /var/www/html/nextcloud </span><span class="tag"></Directory></span>
保存并退出文件。重新启动 Apache 以使更改生效:
<span class="pln">sudo systemctl restart apache2</span>
第 7 步。使用 Let’s Encrypt SSL 保护 Nextcloud。
Certbot 是一种工具,可简化获取和续订 SSL 证书的过程。安装 Certbot 和 Apache 插件:
<span class="pln">sudo apt install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">apache</span>
运行 Certbot 以获取并安装 SSL 证书:
<span class="pln">certbot </span><span class="pun">--</span><span class="pln">apache</span>
第 8 步。通过 Web 浏览器访问 Nextcloud。
打开 Web 浏览器并导航到 。您将看到 Nextcloud 设置页面。https://[your_domain]
感谢您使用本教程在 Debian 12 Bookworm 上安装最新版本的 Nextcloud。如需更多帮助或有用信息,我们建议您查看 Nextcloud 官方网站。