Você está na página 1de 10

Instalação do Nextcloud +

HTTP2 + HTTPS + Debian


Buster – Seu próprio servidor
de arquivos em nuvem!
POR RUDIMAR REMONTTI · PUBLISHED 17 DE SETEMBRO DE 2019 · UPDATED 25
DE AGOSTO DE 2020
Nextcloud tem funcionalidade muito semelhante ao Dropbox, com a
diferença de ser código aberto, e assim permitir que qualquer pessoa
instalar e operá-lo sem custo em um servidor privado. Nextcloud é um
fork do projeto ownCloud.

Requisito:
1- Debian 10 Stretch / Instalação Limpa
2- Passo-a-passo como criar um servidor WEB Apache + PHP +
MariaDB + phpMyAdmin no Debian 10 Buster “LAMP”
Instalação do PHP 7.3 (Requisito)
Instalação do MariaDB 10.3 (Requisito)
Instalação do Apache 2.4 (Requisito)
phpMyAdmin :: (Opcional)
Para a instalação irei configurar um domínio virtual no apache. Leia
para entender mais sobre domínios virtuais:
Como ter diversos sub/domínios no mesmo servidor? (Domínios
virtuais com Apache2)
Tenha então em seu servidor DNS a configuração do host cloud (ou
nome que você preferir) apontando para o IP de seu servidor.

Instalamos mais algumas extensões necessárias do PHP e o redis


para fazer caching da memória.

1 # apt install php-fpm php-pclzip php-xmlrpc php-imagick php-redis redis-server php-memcached


2 php-apcu php-imap php-ldap php-intl
# usermod -a -G redis www-data
Altere o limite de memória do PHP para pelo menos 512M

1 # sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/7.3/fpm/php.ini


Desativamos/Ativamosos mods necessários.

1 # a2enmod proxy_fcgi setenvif mpm_event rewrite headers http2


2 # a2dismod php7.3
3 # a2enconf php7.3-fpm
4 # systemctl enable php7.3-fpm
5 # systemctl restart php7.3-fpm
6 # systemctl restart apache2
Criamos o arquivo que vai representar o host cloud. Vou utilizar como
base o diretório /var/www/cloud que vamos criar em seguida.
Não vou entrar em detalhes da criação das configurações, pois
basta ler o tutorial citado.

1 # vim /etc/apache2/sites-available/cloud.conf

1 <virtualhost *:80>
2         Protocols h2 http/1.1
3         ServerName cloud.remontti.com.br
4         ServerAdmin noc@remontti.com.br
5  
6         DocumentRoot /var/www/cloud
7  
8         <IfModule mod_headers.c>
9           Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
10         </IfModule>
11  
12         <directory /var/www/cloud/ >
13                 Options FollowSymLinks
14                 AllowOverride All
15         </directory>
16  
17         LogLevel warn
18         ErrorLog ${APACHE_LOG_DIR}/error_cloud.log
19         CustomLog ${APACHE_LOG_DIR}/access_cloud.log combined
20 </virtualhost>

1 # a2ensite cloud
2 # systemctl restart apache2
3 # mkdir /var/www/cloud
Para ficar bacana vamos obter um certificado grátis com o Let’s
Encrypt. Leia o tutorial: Criando certificado grátis com Let’s Encrypt
para o Apache no Debian 10

1 # su -
2 # apt update
3 # apt upgrade
4 # apt install letsencrypt python-certbot-apache
5 # systemctl stop apache2
6 # letsencrypt --authenticator standalone --installer apache -d cloud.remontti.com.br

1 Saving debug log to /var/log/letsencrypt/letsencrypt.log


2 Plugins selected: Authenticator standalone, Installer apache
3 Enter email address (used for urgent renewal and security notices) (Enter 'c' to
4 cancel): noc@remontti.com.br
5  
6 ----------------------------------------
7 Please read the Terms of Service at
8 https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
9 agree in order to register with the ACME server at
10 https://acme-v02.api.letsencrypt.org/directory
11 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12 (A)gree/(C)ancel: A
13  
14 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 Would you be willing to share your email address with the Electronic Frontier
16 Foundation, a founding partner of the Let's Encrypt project and the non-profit
17 organization that develops Certbot? We'd like to send you email about our work
18 encrypting the web, EFF news, campaigns, and ways to support digital freedom.
19 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 (Y)es/(N)o: N
21 Obtaining a new certificate
22 Performing the following challenges:
23 http-01 challenge for cloud.remontti.com.br
24 Waiting for verification...
25 Cleaning up challenges
26 Created an SSL vhost at /etc/apache2/sites-available/cloud-le-ssl.conf
27 Enabled Apache socache_shmcb module
28 Enabled Apache ssl module
29 Deploying Certificate to VirtualHost /etc/apache2/sites-available/cloud-le-ssl.conf
30 Enabling available site: /etc/apache2/sites-available/cloud-le-ssl.conf
31  
32 Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
33 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 1: No redirect - Make no further changes to the webserver configuration.
35 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
36 new sites, or if you're confident your site works on HTTPS. You can undo this
37 change by editing your web server's configuration.
38 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
40  
41 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 Congratulations! You have successfully enabled https://cloud.remontti.com.br
43  
44 You should test your configuration at:
45 https://www.ssllabs.com/ssltest/analyze.html?d=cloud.remontti.com.br
46 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47  
48 IMPORTANT NOTES:
49 - Congratulations! Your certificate and chain have been saved at:
50    /etc/letsencrypt/live/cloud.remontti.com.br/fullchain.pem
51    Your key file has been saved at:
52    /etc/letsencrypt/live/cloud.remontti.com.br/privkey.pem
53    Your cert will expire on 2019-12-16. To obtain a new or tweaked
54    version of this certificate in the future, simply run certbot again
55    with the "certonly" option. To non-interactively renew *all* of
56    your certificates, run "certbot renew"
57 - Your account credentials have been saved in your Certbot
58    configuration directory at /etc/letsencrypt. You should make a
59    secure backup of this folder now. This configuration directory will
60    also contain certificates and private keys obtained by Certbot so
61    making regular backups of this folder is ideal.
62 - If you like Certbot, please consider supporting our work by:
63  
64    Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
65    Donating to EFF:                    https://eff.org/donate-le
Acesse seu domínio com https e o mesmo já deve estar prontinho
para o Nextcloud.

Não esqueça de criar o script para renovar seu certificado


Finalmente vamos a instalação do Nextcloud! Na data de hoje
(set/2019) o projeto se encontra na versão 16.0.4.

1 # apt install unzip wget


2 # cd /tmp/
3 # wget https://download.nextcloud.com/server/releases/nextcloud-16.0.4.zip
4 # unzip nextcloud-*.zip
5 # rm -rf /var/www/cloud/
6 # mv nextcloud /var/www/cloud
7 # chown www-data. /var/www/cloud -R
Crie o banco de dados chamado nextcloud e defina sua senha. Use
o gerador de senhas!

# mariadb -uroot -p -e\


1
"CREATE DATABASE nextcloud character set utf8 collate utf8_bin;\
2
  GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY
3
'SUA_SENHA';"
Abra agora em seu navegador https://cloud.dominio.com.br e colocar
as informações para criar sua conta de administrador, e para conexão
com o banco de dados.
Clique em concluir configurações e aguarde o Nextcloud fazer a
instalação.

Ao concluir você a seguinte tela ira aparecer:

Para não criar toda vez que adicionar um novo usuario esses arquivos
padrões que para mim é só lixo, edite o config.php e adicione
‘skeletondirectory’ => ”, aproveitando já adicionamos os idiomas
defaults e configuramos o mamcache.

1 # vim /var/www/cloud/config/config.php
Adicione a baixo de ‘installed’ => true,

1   'default_language' => 'pt-BR',


2   'default_locale' => 'pt_BR',
3   'skeletondirectory' => '',
4   'memcache.local' => '\\OC\\Memcache\\APCu',
5   'memcache.distributed' => '\\OC\\Memcache\\Redis',
6   'redis' =>
7   array (
8     'host' => 'localhost',
9     'port' => 6379,
10   ),
Ficando:

1 <?php
2 $CONFIG = array (
3   'instanceid' => 'xxxxxxxxxxxxxxxxxxxx',
4   'passwordsalt' => 'xxxxxxxxxxxx+xxxxxxxxxxxxx',
5   'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
6   'trusted_domains' =>
7   array (
8     0 => 'cloud.remontti.com.br',
9   ),
10   'datadirectory' => '/var/www/cloud/data',
11   'dbtype' => 'mysql',
12   'version' => '16.0.4.1',
13   'overwrite.cli.url' => 'https://cloud.remontti.com.br',
14   'dbname' => 'nextcloud',
15   'dbhost' => 'localhost',
16   'dbport' => '',
17   'dbtableprefix' => 'oc_',
18   'mysql.utf8mb4' => true,
19   'dbuser' => 'nextcloud',
20   'dbpassword' => 'xxxxxxxxxxxxxxxxxxxx',
21   'installed' => true,
22   'default_language' => 'pt-BR',
23   'default_locale' => 'pt_BR',
24   'skeletondirectory' => '',
25   'memcache.local' => '\\OC\\Memcache\\APCu',
26   'memcache.distributed' => '\\OC\\Memcache\\Redis',
27   'redis' =>
28   array (
29     'host' => 'localhost',
30     'port' => 6379,
31   ),
32 );
Acesse o menu de Configurações e em seguida o menu Visão Geral e
certifique-se que está tudo ok!
Faça um testes em:
https://scan.nextcloud.com/
https://tools.keycdn.com/http2-test
Se desejar pode instalar as versões desktop ou mobile.

Outras melhorias que podem ser aplicadas.


1 # vim /etc/mysql/conf.d/mysql.cnf

1 [mysqld]
2 innodb_buffer_pool_size=1G
3 innodb_io_capacity=4000

1 # vim  /etc/php/7.3/fpm/conf.d/10-opcache.ini

1 ; configuration for php opcache module


2 ; priority=10
3 zend_extension=opcache.so
4  
5 opcache.enable=1
6 opcache.enable_cli=1
7 opcache.interned_strings_buffer=8
8 opcache.max_accelerated_files=10000
9 opcache.memory_consumption=256
10 opcache.save_comments=1
11 opcache.revalidate_freq=1

1 # systemctl restart php7.3-fpm apache2

Você também pode gostar