Hello, today I'm going to teach how to install Nextcloud on a Debian machine, using Portainer to manage all your docker containers and nginx proxy manager, to have SSL connection.
For those who don't know about Nextcloud, I highly recommend taking a look at their page. It is an open source software that enables you to handle your data, for those who have concerns about privacy, and do not trust google, apple ... Nextcloud provides a way to you store your files and photos, manage your calendar, save contacts and much more... And it is free.
I will provide a GitHub with all the files you need to set up, your Nextcloud instance.
For this tutorial, I'm assuming that you have already a domain and ave set up your subdomains in your VPS manager.
Before we start, you need to open connections for ports, in your firewall.
- 81
- 9000
- 8080
After we set up nginx, we can close the connection on those ports and use only the subdomain that we will set up on nginx proxy manager.
- Open the folder *//nextcloud/, and edit the file /.env/:
Define values for all the following attrs:
{user_password}
{db_user}
{db_password}
{redis_password}
{nc_admin_user}
{nc_admin_password}
{your.domain.com}
{timezone} # America/Winnipeg
- Edit the file /docker-compose.yml/ inside the folder //nextcloud/;
{redis_password}
- Open the folder //npm/, and edit the file /.env/;
Define values for all the following attrs:
{npm_db_password}
{npm_db_name}
{npm_db_user}
{npm_db_password}
Here we also deploy a MariaDB container, but this is only for nginx proxy manager to persist its data.
First we need to install /docker/, /docker-compose/ and /portainer/ on our machine.
Connect via ssh or use /FileZilla/ or /putty/ to upload the file. In this step, we will install all dependencies on your machine to run docker and Portainer.
-
Upload the script /setup.sh/ to your machine;
-
Run the following commands:
- To give permission to the file to be executable.
chmod +x setup.sh
- Run the script to install all the dependencies, be aware that you will need to accept some terms.
./setup.sh
-
Wait until the installation finishes.
-
Open in your browser /{your_vps_ip}:9000/ and set up an admin account for Portainer.
Portainer agent add some more functionality to your portainer CE.
-
Go to Environments in you portainer and add a new one;
-
in Environment URL you will add your {host_ip}:9001;
-
In case that you have setup and HTTPS domain you can add it to public ip;
-
Add a name and create the environment.
Some of the features that portainer agent enables is, to browse you volumes through the interface, without the need to connect via FTP or SSH to change files for example.
Nginx proxy manager it is a container with an application that makes it easier to configure nginx, if you have knowledge and experience with nginx you can also configure using him directly, this is just a friendly UI.
-
In you Portainer;
-
Go to Stacks → + add stack → upload.
-
Select the file from my repository /npm/docker-compose.yml/;
-
Also upload the .env file.
-
Deploy the stack that you have created.
-
Open /{your_vps_ip}:81/, log with the following account and change your password after it.
[email protected]
changeme
Here we will configure three domains, example:
- portainer.rodrigo.com.br → To access your Portainer application;
- drive.rodrigo.com.br → To access your Nextcloud application;
- proxy.rodrigo.com.br → To access your nginx proxy manager application;
- office.rodrigo.com.br → To access your onlyoffice instance (you will not access directly this URL, nextcloud will use it);
Check the image on /images/npm_hosts_example/ to see how it needs to be after you create the four hosts.
- Go to hosts → Proxy hosts and create a new one, this configuration is valid for all the four hosts
- Tab detail: Check Cache assets, block common exploits and web sockets support;
- Tab SSL: Force SSL, HTTP/2 and HSTS enabled;
For Nextcloud, add the following lines to advanced tab, custom nginx configuration:
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 16384m;
client_max_body_size 0;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
- Now you should be able to access your Portainer and NPM application using the domains you just set up.
-
Go to Stacks → + add stack → upload.
-
Select the file from my repository /nextcloud/docker-compose.yml/;
-
Also upload the .env file.
-
Deploy the stack that you have created;
-
In your browser, open /{your_vps_ip}:8080/, to create the config.php file;
-
In Portainer select the Nextcloud container and click on
exec a new console
, to connect to the Nextcloud container;
Run the following command inside the /config folder to install vim and create a config.php file, where we will add some configurations to Nextcloud;
apt-get update && apt-get install vim && vim config.php
- Add the following code to the config.php file;
'redis' =>
array (
'host' => 'redis',
'port' => 6379,
'password' => '{redis_password}',
),
'filelocking.enabled' => true,
'memcache.locking' => '\OC\Memcache\Redis',
'default_phone_region' => 'BR',
'trashbin_retention_obligation' => '30, 60',
'overwriteprotocol' => 'https',
'default_language' => 'pt_BR',
'default_locale' => 'pt_BR',
'log_type' => 'file',
'logfile' => 'nextcloud.log',
'logdateformat' => 'F d, Y H:i:s',
'maintenance' => false,
Save and restart the Nextcloud instance;
-
Type in your browser the domain that you have set up for Nextcloud, example: nextcloud.rodrigo.com.br;
-
Set up an admin account and select MySQL/MariaDB
-
Important, you need to click on Storage & Database to set up MySQL/MariaDB;
-
Fill the database credentials, those same that you have set up before on the nextcloud.env file;
-
The last input is the IP to connect to your MariaDB container; 1. You need to go back to Portainer and get the IP that was attached to the Nextcloud MariaDB container. {container_ip}:3306, do not forget to add the port 3306 at the end.
-
Now your Nextcloud is up and running, congratulations.
Note: You may want to change the default cron time, the default is 3 minutes, you can change it inside the file nextcloudcron.timer, changing the variable OnUnitActiveSec.
-
Copy the two files inside the /systemd folder to /etc/systemd/system/ of your host machine.
-
Run the following command to start the job on the system boot;
systemctl enable nextcloud-cron.timer
- Run the following command to start the job at once;
systemctl start nextcloud-cron.timer
- And run the following command to check the status;
systemctl status nextcloud-cron.timer
If you want to run the job to generate previews, you need to run the same commands for nextcloud-preview-generator.timer and nextcloud-preview-generator.service.
With onlyoffice you can have the same functionalities that you have on Google Drive to create slides, documents, sheets ...
-
Add a new stack on portainer with the name onlyoffice and upload the docker-compose.yml inside the folder /onlyoffice;
-
Open nextcloud with your admin account, add the onlyoffice plugin;
-
Open setting menu and click on onlyoffice option;
-
Add your domain to ONLYOFFICE Docs address (domain that you previous setup on npm, office.rodrigo.com.br);
-
And to finish, you can change the configuration following the image only_office_example on /images;
In case that you have problems to set up your domain at NPM, be aware that for own domain, example: nextcloud.rodrigo.com.br you have a limit of 5 certificates within 168 hours. So let's encrypt will generate only five SSL certificates, if you reach the limit you need to test with a different subdomain.