如何在 Ubuntu 22.04 LTS 上安装 OwnCloud

在本教程中,我们将向您展示如何在 Ubuntu 22.04 LTS 上安装 OwnCloud。 对于那些不知道的人,OwnCloud 是用 PHP 编写的免费开源软件,用于数据同步和文件共享。 作为 Web 浏览器的替代方案,ownCloud 为 Microsoft Windows、macOS 和 Linux 发行版提供桌面客户端。 ownCloud 可在不同的添加中使用,如其上突出显示的那样 定价页面.

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 22.04 (Jammy Jellyfish) 上逐步安装 OwnCloud 云存储服务。 对于 Ubuntu 22.04 和任何其他基于 Debian 的发行版,如 Linux Mint、Elementary OS、Pop!_OS 等,您可以按照相同的说明进行操作。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 22.04、20.04 和任何其他基于 Debian 的发行版,如 Linux Mint。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一个 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 OwnCloud

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt 终端中的命令。

sudo apt update sudo apt upgrade

步骤 2. 在 Ubuntu 22.04 上安装 LAMP 堆栈。

在开始本教程之前,必须在您的服务器上安装 LAMP 服务器。 如果您没有安装 LAMP Stack,您可以在此处按照我们的指南进行操作。

步骤 3. 在 Ubuntu 22.04 上安装 OwnCloud。

默认情况下,OwnCloud 在 Ubuntu 22.04 基础存储库中不可用。 现在运行以下命令,将最新稳定版本的 OwnCloud 下载到您的 Ubuntu 系统:

wget https://download.owncloud.com/server/stable/owncloud-complete-latest.zip

下载完成后,我们需要解压到 /var/www/html/ 目录:

unzip owncloud-complete-latest.zip -d /var/www/html/

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

chown -R www-data:www-data /var/www/html/owncloud/

步骤 4. 为 OwnCloud 配置 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 控制台并为 OwnCloud 创建一个数据库。 运行以下命令:

mysql -u root -p

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

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

步骤 5. 配置 Apache 为自己的云。

现在我们创建一个 Apache OwnCloud 的虚拟主机:

nano /etc/apache2/sites-available/owncloud.conf

添加以下文件:

<VirtualHost *:80>  ServerAdmin [email protected]  DocumentRoot /var/www/html/owncloud/  ServerName your-domain.com  ServerAlias www.your-domain.com   ErrorLog ${APACHE_LOG_DIR}/error.log  CustomLog ${APACHE_LOG_DIR}/access.log combined   <Directory /var/www/html/owncloud/>         Options FollowSymlinks         AllowOverride All         Require all granted  </Directory> </VirtualHost>

Save 和 close 文件,然后重新启动 Apache 网络服务器,以便进行更改:

sudo a2ensite owncloud.conf sudo a2enmod rewrite sudo a2enmod ssl rewrite sudo systemctl restart apache2

步骤 6. 使用 Let’s Encrypt 保护 OwnCloud。

首先,您需要安装 Certbot 以使用 Let’s Encrypt 获取 SSL 证书:

sudo apt install certbot python3-certbot-apache

接下来,按照以下步骤使用 Let’s Encrypt 获取您的 SSL 证书:

sudo certbot --apache

您将需要按照交互式提示安装证书。 由于我有两个域,我将为两个域安装 SSL 证书:

Saving debug log to /var/log/letsencrypt/letsencrypt.log Enter email address (used for urgent renewal and security notices)  (Enter 'c' to cancel): [email protected]  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server. Do you agree? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N Account registered.  Which names would you like to activate HTTPS for? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: your-domain.com 2: www.your-domain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel): 1,2 Requesting a certificate for your-domain.com and www.your-domain.com Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/your-domain.com/fullchain.pem Key is saved at:         /etc/letsencrypt/live/your-domain.com/privkey.pem This certificate expires on 2022-12-16. These files will be updated when the certificate renews. Certbot has set up a scheduled task to automatically renew this certificate in the background.  Deploying certificate Successfully deployed certificate for domain.com to /etc/apache2/sites-available/www.your-domain.com-le-ssl.conf Successfully deployed certificate for www.domain.com to /etc/apache2/sites-available/www.your-domain.com-le-ssl.conf Congratulations! You have successfully enabled HTTPS on https://domain.com and https://www.your-domain.com  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If you like Certbot, please consider supporting our work by:  * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate  * Donating to EFF:                    https://eff.org/donate-le - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

步骤 7. 设置自动续订 SSL。

Let’s Encrypt 证书的有效期为 90 天,强烈建议在证书到期前更新证书。 您可以通过运行以下命令来测试证书的自动续订:

sudo certbot renew --dry-run

步骤 8. 配置防火墙。

现在我们设置一个简单的防火墙(UFW) Apache 允许对 HTTP 和 HTTPS 的默认 Web 端口进行公共访问:

sudo ufw allow OpenSSH sudo ufw allow 'Apache Full' sudo ufw enable

步骤 9. 访问 OwnCloud Web 界面。

成功安装后,打开 Web 浏览器并使用 URL 访问 OwnCloud 安装向导 https://your-domain.com. 您将被重定向到以下页面:

恭喜! 您已成功安装 OwnCloud。 感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装带有 LAMP 的 OwnCloud。 如需更多帮助或有用信息,我们建议您查看 OwnCloud 网站.