AWS S3-based enterprise network file sharing using Nextcloud

Hardware prerequisites

Let’s put something together using Ubuntu.

Hardware and software requirements for both recommended and minimal Nextcloud installations
  • One sever with 2 CPU cores
  • 16GB of RAM
  • Authentication through Lightweight Directory Access Protocol (LDAP) (a widely-used distributed information protocol)
  • Red Hat Enterprise Linux or Ubuntu 16.04 _with_ vendor support
    Apache with TLS/SSL encryption certificate
  • The MySQL or MariaDB database
  • The Btrfs file system mounted with _nodatacow_ for Nextcloud data partitions to permit _zero downtime_ backups
  • Caching with memcache to speed up access performance

Building a LAMP server

Building a base environment suitable for testing the package should be simple enough. Here are all the packages you’ll need for your server in a single command. I threw in wget and nano just in case they’re not already installed. In the interest of keeping the base image as small as possible, packages like nano are often not installed by default on some virtualized platforms like LXC containers.

# apt install apache2 mariadb-server libapache2-mod-php7.0 \
php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring \
php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip \
wget nano
 # apt install lamp-server^
# mysql_secure_installation 
MariaDB [(none)]> SET PASSWORD = PASSWORD(‘your-password’);
MariaDB [(none)]> update mysql.user set plugin = ‘mysql_native_password’ where User=’root’;
MariaDB [(none)]> FLUSH PRIVILEGES;

Apache configuration

To ensure that Apache will be able to communicate with Nextcloud, there are a few relatively simple adjustments you’re going to have to make. First off, you should enable a couple of Apache modules through the a2enmod tool. The rewrite module is used to rewrite URLs in real time as they’re moved between a client and the server. The headers module performs a similar function for HTTP headers.

# a2enmod rewrite
# a2enmod headers
Alias /nextcloud “/var/www/nextcloud/”<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/nextcloud
SetEnv HTTP_HOME /var/www/nextcloud
</Directory>
<VirtualHost *:443> <1>
ServerName bootstrap-it.com
DocumentRoot /var/www/nextcloud
ServerAlias bootstrap-it.com/nextcloud <2>
</VirtualHost>
Apache reads configuration files in /etc/apache2/sites-enabled/ and uses their settings to redirect requests
# ln -s /etc/apache2/sites-available/nextcloud.conf \
/etc/apache2/sites-enabled/nextcloud.conf

Downloading and unpacking Nextcloud

You can download the most recent Nextcloud package from the Nextcloud Install page. If you’re installing to a container or VM — or from a server without a desktop GUI installed — then the most convenient approach is to get the package’s download URL and grab the package from the command line.

Links to Nextcloud download archives: either the .tar.bz2 or the .zip formats will work
$ wget https://download.nextcloud.com/server/releases/nextcloud-12.0.0.tar.bz2 
$ tar xjf nextcloud-12.0.0.tar.bz2
# cp -r nextcloud /var/www/ 
# chown -R www-data:www-data /var/www/nextcloud/
# systemctl restart apache2
# journalctl | tail
10.0.3.36/nextcloud
The main Nextcloud console, complete with sample folders and files — you can work with objects here just as you would using an OS file manager

Using AWS S3 as your primary Nextcloud storage

The thing about storing stuff is that you have to find space to put it all. And, since all storage devices will eventually fail without warning, you’ll need multiple copies of each device. Figuring out how to provision, connect, and maintain such storage arrays is time consuming, and keeping it going is relatively expensive.

The list of currently available apps, including External storage support

Connect Nextcloud to an S3 bucket

From the command line on any computer with the AWS CLI installed and configured for your AWS account (see chapter 12 of my AWS in a Month of Lunches book for details), create a new bucket with a globally unique name.

$ aws s3 mb nextcloud32327
The External storages setup page for Amazon S3, showing a successful connection to my S3 bucket
$ aws s3 ls s3://nextcloud32327
testfile.pdf
$ aws s3 cp test.txt s3://nextcloud32327

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David Clinton

David Clinton

894 Followers

Linux system admin and tech training content provider. Known to hang out at https://bootstrap-it.com.