Please make sure you already have Ubuntu 18.04 installed and updated.
Install the Nextcloud
1: Install the Nextcloud Snap Package
sudo snap install nextcloud
Login to you server IP to provide with admin user name and password. You can avoid this step by manually setting up new administrator account.
sudo nextcloud.manual-install adminusername adminpassword
2: Adjust the Trusted Domains
sudo nextcloud.occ config:system:set trusted_domains 1 --value=example.com
You can check if new domain is added by entering following code
sudo nextcloud.occ config:system:get trusted_domains
At this point you should be able to login to nextcloud using IP or domain name. Please note you might have to make change to Firewall settings before you can access port 80.
Setting up SSL with Let's Encrypt
1: Make changes to firewall
sudo ufw allow 80,443/tcp
2: Next, request a Let’s Encrypt certificate by typing:
sudo nextcloud.enable-https lets-encrypt
You will first be asked whether your server meets the conditions necessary to request a certificate from the Let’s Encrypt service:
Type y to continue.
Next, you will be asked to provide an email address to use for recovery operations:
Please enter an email address (for urgent notices or key recovery): firstname.lastname@example.org
Finally, enter the domain name associated with your Nextcloud server:
Please enter your domain name(s) (space-separated): example.com
If all good you should see the following.
Output Attempting to obtain certificates... done Restarting apache... done