How to Set Up AWS S3-Based Enterprise File Sharing with Nextcloud

Are you looking for a secure, flexible, and cost-effective way to enable file sharing across your organization? Combining the open source Nextcloud platform with Amazon S3 storage provides a powerful solution for enterprise file sync and share.

In this guide, we‘ll walk through the process of setting up Nextcloud on a Linux server and configuring it to use S3 as the primary storage backend. With this setup, you get the rich collaboration features of Nextcloud as well as the scalability, durability, and low costs of cloud object storage. Let‘s get started!

Why Use Nextcloud with S3?

Nextcloud is a popular open source platform that provides Dropbox-like file sharing capabilities which you can host yourself. Some key features include:

  • Sync files across devices
  • Share files and folders with other users
  • Collaborate on documents in real-time
  • Communicate through chat, voice, and video calls
  • Extend functionality via apps and integrations

By installing Nextcloud on your own Linux server, you retain full control over your data and can customize the platform to fit your needs. However, storing terabytes of data yourself introduces challenges around provisioning, scaling, and protecting all that storage.

That‘s where Amazon S3 comes in. S3 is a fully managed object storage service that offers:

  • Virtually unlimited scalability
  • 99.999999999% durability
  • Low cost pay-as-you-go pricing
  • Strong security and compliance

Using S3 as the storage backend for Nextcloud provides the best of both worlds. You benefit from the rich functionality of Nextcloud while leveraging S3 to cheaply and reliably store all the data. And you avoid the high costs and operational complexity of local storage.

Hardware and Software Requirements

Before we dive into installation, let‘s review the hardware and software needed to run Nextcloud. For testing purposes, a basic setup will work:

  • 2 CPU cores
  • 4 GB RAM
  • 20 GB disk space
  • Ubuntu Server 20.04 LTS

For production use with hundreds of users and terabytes of storage, Nextcloud recommends:

  • 4-8 CPU cores
  • 16-32 GB RAM
  • Separate disks for OS and data
  • RAID array for data redundancy
  • MySQL or PostgreSQL database
  • Redis cache server
  • Nginx or Apache web server w/ SSL

In terms of software, we‘ll use Ubuntu 20.04 LTS, Apache 2.4, MariaDB 10.3, PHP 7.4, and the latest Nextcloud 21 release.

Install Apache, PHP, and MariaDB

Let‘s start by installing the Apache web server, PHP runtime, and MariaDB database server that Nextcloud requires. On Ubuntu, you can install them with:

sudo apt update
sudo apt install apache2 mariadb-server libapache2-mod-php7.4 \
    php7.4-gd php7.4-json php7.4-mysql php7.4-curl \
    php7.4-mbstring php7.4-intl php7.4-gmp php7.4-bcmath \
    php-imagick php7.4-xml php7.4-zip

Next, configure a few recommended settings in PHP and Apache:

sudo nano /etc/php/7.4/apache2/php.ini

Find the following settings and set their values:

memory_limit = 512M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 300
date.timezone = America/New_York

Save and close the file. Then enable some Apache modules:

sudo a2enmod rewrite headers env dir mime
sudo systemctl restart apache2

Secure the MariaDB installation:

sudo mysql_secure_installation

Answer the prompts to set a root password, remove anonymous users, disable remote root login, and remove the test database.

Download and Install Nextcloud

Now we‘re ready to download and install Nextcloud itself. Grab the latest release from the Nextcloud website:

cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-21.0.1.tar.bz2

Verify the checksum:

md5sum nextcloud-21.0.1.tar.bz2

Extract the archive and copy it to the Apache web root:

tar -xjf nextcloud-21.0.1.tar.bz2
sudo cp -r nextcloud /var/www/

Create a data directory outside the web root for added security:

sudo mkdir -p /var/nextcloud/data

Set proper permissions on the directories :

sudo chown -R www-data:www-data /var/www/nextcloud 
sudo chown -R www-data:www-data /var/nextcloud

Create an Apache configuration file for Nextcloud:

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

Paste in the following config:

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

<Directory /var/www/nextcloud/>
  Require all granted
  AllowOverride All
  Options FollowSymLinks MultiViews

  <IfModule mod_dav.c>
    Dav off
  </IfModule>

  SetEnv HOME /var/www/nextcloud
  SetEnv HTTP_HOME /var/www/nextcloud
</Directory>

Enable the config and restart Apache:

sudo a2ensite nextcloud.conf
sudo systemctl restart apache2

Configure Nextcloud

Open a web browser and navigate to your server hostname or IP address followed by /nextcloud. You should see the Nextcloud setup screen.

Create an admin account and specify the data directory you created earlier (/var/nextcloud/data). For the database, select MySQL/MariaDB and enter the root credentials.

Click "Finish Setup" and wait for the initialization to finish. You can then log in with your new admin account and begin using Nextcloud.

Add S3 as External Storage

The last step is configuring Nextcloud to use S3 for primary storage. Log into the admin account and click your user icon in the top-right and select "Apps".

Click the "Disabled apps" tab on the left and find "External storage support". Click "Enable" to activate it.

Next, click your user icon again and select "Settings". Click "External storages" in the Administration section.

Click the "Add storage" button and select "Amazon S3" from the menu. Enter the following details:

  • Folder name: choose a name to display
  • Bucket: enter the name of your S3 bucket
  • Access Key: enter your S3 access key
  • Secret Key: enter your S3 secret key

Click the checkbox to save. The storage should now show as "green" and enabled. All newly uploaded files will be stored in S3 instead of locally.

Conclusion

And that‘s it! You now have a fully functional Nextcloud server that stores all data in low-cost, durable S3 storage. Your users can sync and share files just like Dropbox, while you maintain full control over your data.

Some next steps to consider are configuring SSL certificates, setting up user directories, enabling server-side encryption, and connecting Nextcloud apps like Calendar and Contacts.

The power and flexibility this setup provides makes it an excellent option for any organization looking to enable file sharing in a secure, compliant, and cost-effective way. The combination of Nextcloud and AWS S3 delivers the best of both self-hosted and cloud storage.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *