Deploying a Nextcloud Instance
7 June 2023
I stumbled across the Nextcloud software and decided it would be fun to run my own instance of it with the spare compute power on my server. I bought an AWS savings plan, so I'm basically losing money by not running it.
I decided to put Nextcloud on a seperate machine/server/VPS from this website. I'm starting to get to the point where managing and configuring everything is easier if I keep them seperate. To reduce the additional costs, I stopped running the Minecraft server (that never got used) and downgraded the website from a T3 Small to a T3 Micro. This is reducing the RAM and cost by half, but the website still runs just fine. Nextcloud will go on another T3 Micro instance, so overall my cost for instances doesn't change.
Nextcloud can use external storage services like the AWS S3, so I made the new instances drive only 10GB. I created a S3 bucket (all default settings); I'll configure Nextcloud to store user files in it once it's running.
I created the T3 instance, 10GB EBS volume, running Ubuntu. I gave it a static IP and made a DNS entry to point to it, using a subdomain of akbatten.com. With this set up, I SSH'ed in and installed the sanp version of Nextcloud with:
sudo snap install nextcloud
The snap package is less customizable, but comes with everything needed. This way I can avoid configuring an apache server, SQL database, etc.
I then configured Nextcloud to use the S3 bucket. The official docs list everything you need to add to the config.php file to get this to work. For S3, I made an AWS user just for nextcloud to access the S3 bucket, giving it full S3 permissions. This could probably be reduced in scope later. I had to add an access key after creating the user, even though the AWS instructions show adding it during creation.
With everything set up, I added the appropriate information into the config.php file:
<?php $CONFIG = array ( 'objectstore' => array ( 'class' => '\\OC\\Files\\ObjectStore\\S3', 'arguments' => array ( 'bucket' => 'mybucket22', 'region' => 'us-east-1', 'key' => 'userKey', 'secret' => 'userSecretDONOTLETTHISLEAK', ), ), 'apps_paths' => <continued>
Nextcloud will now store all user files in the S3 bucket. Note that if you do this after files start to get stored, Nextcloud will not copy them over, so you'll lose the files. I assume you could recover them from where they're stored on the server if needed.
Everything on the backend should be configured, so the last thing to do is navigate to your nextcloud instance and walk through the automated setup. This will create the default (admin) user and get everything started.
One thing I ended up changing was the addition of a swap file on the server. I found that 1GB RAM was not enough when upload many files and Nextcloud kept disconnecting and being annoying. After making a swap file (1GB), everything feels much smoother. The performance impact of using the disk instead of RAM is not noticable for this application.