如何在Debian 10上安装NextCloud

如何在Debian 10上安装NextCloud

NextCloud是一个免费的开源文件托管和文件共享服务器,它是由ownCloud项目创建的。与其他文件共享服务(例如Google Drive,Dropbox,iCloud)非常相似。使用NextCloud,您可以从中央位置存储文件,文档,照片,电影和视频。使用NextCloud,您可以与朋友和客户端共享文件,联系人和其他媒体。 NextCloud与电子邮件,日历,联系人和其他功能集成在一起,以帮助您的团队更快,更轻松地工作。您可以在台式机上安装NextCloud客户端,然后将文件与Nextcloud服务器同步。桌面客户端可用于大多数操作系统,包括Windows,macOS,FreeBSD和Linux。

本教程介绍了如何安装NextCloud以及如何在Debian 10上使用Let’s Encrypt SSL对其进行保护。

先决条件

  • 运行Debian 10的服务器。
  • 服务器IP中指定的有效域名。本教程使用nextcloud.example.com域。
  • 根密码是在服务器上设置的。

安装Apache,MariaDB,PHP

NextCloud在用PHP编写的Web服务器上运行,并使用MariaDB存储数据。因此,您需要在系统上安装Apache,MariaDB,PHP和其他必需的软件包。您可以通过运行以下命令来全部安装它们:

apt-get install apache2 libapache2-mod-php mariadb-server php-xml php-cli php-cgi php-mysql php-mbstring php-gd php-curl php-zip wget unzip -y

安装完所有软件包后,打开php.ini文件并调整一些建议的设置。

nano /etc/php/7.3/apache2/php.ini

更改以下设置:

memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 300
date.timezone = Asia/Kolkata

完成后,保存并关闭文件。接下来,启动Apache和MariaDB服务,以便可以在系统重新启动后使用以下命令启动它们:

systemctl start apache2 systemctl start mariadb systemctl enable apache2 systemctl enable mariadb

完成后,您可以继续下一步。

配置NextCloud数据库

接下来,您需要创建一个NextCloud数据库和数据库用户。为此,请使用以下命令登录到MariaDB shell:

mysql -u root -p

在出现提示时输入root密码,并使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE nextclouddb; MariaDB [(none)]> CREATE USER 'nextclouduser'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令授予nextclouddb所有特权:

MariaDB [(none)]> GRANT ALL ON nextclouddb.* TO 'nextclouduser'@'localhost';

接下来,刷新特权并使用以下命令退出MariaDB shell:

MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;

完成后,您可以继续下一步。

下载NextCloud

首先,转到NextCloud下载页面,然后将最新版本的NextCloud下载到您的系统。在撰写本文时,NextCloud的最新版本是17.0.1。您可以使用以下命令下载它:

wget https://download.nextcloud.com/server/releases/nextcloud-17.0.1.zip

下载完成后,使用以下命令解压缩下载的文件:

unzip nextcloud-17.0.1.zip

接下来,将提取的目录移动到Apache Web根目录。

mv nextcloud /var/www/html/

接下来,使用以下命令将适当的权限授予nextcloud目录:

chown -R www-data:www-data /var/www/html/nextcloud/ chmod -R 755 /var/www/html/nextcloud/

完成后,您可以继续下一步。

为NextCloud配置Apache

接下来,您需要创建一个Apache虚拟主机配置文件以提供NextCloud。您可以使用以下命令创建它。

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

添加以下行:


     ServerAdmin [email protected]
     DocumentRoot /var/www/html/nextcloud/
     ServerName nextcloud.example.com

     Alias /nextcloud "/var/www/html/nextcloud/"

     
        Options +FollowSymlinks
        AllowOverride All
        Require all granted
          
            Dav off
          
        SetEnv HOME /var/www/html/nextcloud
        SetEnv HTTP_HOME /var/www/html/nextcloud
     

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined


完成后,保存并关闭文件。接下来,使用以下命令启用Apache虚拟主机文件和其他必需的模块:

a2ensite nextcloud.conf a2enmod rewrite a2enmod headers a2enmod env a2enmod dir a2enmod mime

最后,重新启动Apache服务以应用新配置。

systemctl restart apache2

使用免费的SSL加密保护NextCloud

现在已安装和配置NextCloud。接下来,我们建议您使用“让我们加密免费的SSL”保护它。为此,请首先使用以下命令安装Certbot客户端:

apt-get install python-certbot-apache -y

安装完成后,您可以通过运行以下命令来为域nextcloud.example.com安装“让我们加密证书”:

certbot --apache -d nextcloud.example.com

在安装过程中,系统将要求您输入电子邮件地址并接受如下所示的条款和条件。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
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 at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing 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: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for nextcloud.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/nextcloud-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/nextcloud-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/nextcloud-le-ssl.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

然后键入2,然后按Enter键为您的域下载并安装免费的SSL证书。安装成功完成后。您将获得以下输出:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/nextcloud.conf to ssl vhost in /etc/apache2/sites-available/
nextcloud-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://nextcloud.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=nextcloud.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2019-10-22. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - 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

完成后,您可以继续下一步。

访问NextCloud Web界面

通过“让我们加密SSL”来设置和保护NextCloud。接下来,打开您的Web浏览器并输入URL https://nextcloud.example.com。您将被重定向到下一页。

配置数据库

接下来,输入管理员用户名和密码,数据文件夹以及正确的数据库凭据, 完结 设定 按钮您将被重定向到下一页上的NextCloud仪表板。

NextCloud仪表板

现在就这样。

结论

恭喜你!使用“在Debian 10上加密免费SSL”成功安装和保护NextCloud。使用NextCloudWeb界面轻松与他人共享文件,文档和媒体。

Source

Sidebar