Skip to main content

Nextcloud

Version: Latest   |   OS: Ubuntu 22.04

Overview

Nextcloud is a secure and self-hosted content collaboration platform, allowing users to store, sync, and share files, contacts, calendars, and more. It provides full control over data and is ideal for both individual and enterprise use.

Included Software

  • Nextcloud - Latest stable release
  • Apache - 2.4.x
  • MySQL - 8.0.x
  • PHP - 8.1 or 8.2
  • Redis - for caching and session storage
  • Fail2ban - for brute-force protection
  • Certbot - for SSL certificate management
  • Postfix - for sending outbound mail

Getting Started

Firewall & Access

Ensure the following ports are allowed through your firewall:

PortServicePurpose
22SSH (rate limited)Server access
80HTTPWeb traffic
443HTTPSSecure web traffic

Initial Setup Process

Upon first boot:

  • The MySQL root password is set and mysql_secure_installation is run.
  • Apache and PHP are configured.
  • Nextcloud files are placed in the web root.
  • Nextcloud admin credentials and database settings are initialized.

You will be disconnected with the message:

Please wait until the installation is completed....
Connection to $IPADDRESS closed.

Please wait at least 2 minutes before logging back in.

Accessing the Instance

  • Login as ubuntu via SSH.
  • Switch to root:
sudo su -

Admin and database credentials will be displayed on first login. All credentials are stored for future reference in:

  • MySQL root password: /root/.mysql_root_password
  • Nextcloud DB details: /root/.nextcloud_database_details
  • Nextcloud admin login: /root/.nextcloud_admin_credentials

Accessing Nextcloud Dashboard

Visit http://$IPADDRESS or your domain name in a web browser.

  1. Ensure the domain's A record points to your instance.
  2. Set the domain in Nextcloud's trusted domains:
sudo -u www-data php /var/www/html/occ config:system:set trusted_domains 1 --value="yourdomain.com"
  1. Set the server name in Apache:
sed -i 's/#ServerName .*/ServerName yourdomain.com/' /etc/apache2/sites-available/000-default.conf
  1. Restart Apache:
systemctl restart apache2

SSL Setup with Certbot

Use Certbot to secure your Nextcloud instance with HTTPS:

certbot --apache -d yourdomain.com -d www.yourdomain.com

Make sure both A and www A records are properly pointed before running the above command.

Postfix Configuration

  1. Set a valid hostname:
hostnamectl set-hostname your.hostname.com
  1. Ensure PTR and A records exist for the hostname.
  2. Edit /etc/postfix/main.cf:
myhostname = your.hostname.com
  1. Restart Postfix:
systemctl restart postfix
  1. Test email delivery:
echo "Test email from Nextcloud" | mail -s "Subject" you@example.com

Emails may initially land in spam due to new IP reputation.

Best Practices

  • Regularly back up Nextcloud files and its database.
  • Keep your Nextcloud instance updated for security and performance.
  • Use fail2ban and firewall rules to protect from brute-force attacks.
  • Configure external storage and collaborative apps from the Nextcloud app store as needed.

For assistance, contact Cloud4India Support.