Skip to content

Instantly share code, notes, and snippets.

@rrrnld
Last active October 27, 2018 00:47
Show Gist options
  • Save rrrnld/2823f0c1eac9ad41c7ecfb21f2bec9cb to your computer and use it in GitHub Desktop.
Save rrrnld/2823f0c1eac9ad41c7ecfb21f2bec9cb to your computer and use it in GitHub Desktop.
How to use Amazon S3 with koel

How to use Amazon S3 for storing your koel media files

In this short tutorial I will show you a (kind of hacky, but working) option to set up your koel instance so that you can store your media files on S3 as provided by Amazon. I will also share some of the insights and experiences I had with the setup. Be aware that it's not officially supported and it might work differently to from what you expect. I myself have not had the setup running for a very long time yet. Feel free to share your thoughts in the comments below or add to the document.

If you feel like supporting me, maybe use my Digital Ocean referral link when signing up. If you do that, please also support the original authors of the various tools. They did the hard work, I just glued it together.

Basic setup

My setup is based on koel 2.2.0 running on Ubuntu 14.04, PHP 7.0, Maria DB and nginx, where PHP is served through FPM instead of FastCGI. It is loosely based on this guide, but I will not explain it in great detail here. This guide shall only cover the Amazon S3 bits. The S3 integration is done with the awesome goofys "filey system" which allows us to mount S3 buckets like a normal file system and use the most important commands like we would usually do. I chose it over other tools which offered similar functionality (such as s3fs and riofs) because of its light weight and performance. There are a few graphs giving a pretty solid overview if you take a look at the readme found on their github page.

Installation

Note: It is assumed you run all of the following commands as root to install new software packages globally on your system.

  1. Install koel as you usually would and set everything up, up until the point where you name the media storage path
  2. Install goofys and make the executable globally available on your system:
  3. cd /opt
  4. wget https://github.com/kahing/goofys/releases/download/v0.0.5/goofys
  5. chmod +x goofys
  6. ln -s ./goofys /usr/local/bin/goofys
  7. Install fuse-utils. I could not mount the bucket without it: apt-get install fuse-utils
  8. Configure your AWS credentials as described in the goofys docs. Configure it in /root for the next step to work.
  9. Create the entry in /etc/fstab. Mount using mount -a. You should now be able to see your files: ls -l /mnt/path_to_your_bucket.
  10. All that's left now is configuring koel to point to your new shiny s3 file system root, /mnt/path_to_your_bucket. You might need to do this for your nginx config as well.

Voilá! That's it! You can now access your files over the koel web interface.

Further notes

As I have said, I do not have this configuration running for a very long time, so take all of this with a grain of salt.

I can confirm that x-accel-send works with this configuration. I can also scan for new files by firing up php artisan koel:sync. What did not work for me was initiating a scan over the web interface. I was just receiving an Unknown error so I can't really tell what the issue was, but to be honest I also did not spend a lot of time debugging it. As for the performance: It is unnoticable to me when streaming the music. The latency is at least an order of magnitude smaller than the length of any track I listen to (and that would still be true if you're into Grindcore I guess). As for scanning: It worked pretty well as long as I had around 300 tracks, or 3.2GB (the audio I listen to usually are 320kbit MP3s give or take) and scanning would take me maybe five minutes. I am still unsure what exactly changed (maybe single large files that I have added or the provider has throttled traffic) but scanning a total of 511 songs at 4.6GB now takes about 40 minutes. I estimate to nevertheless still be in the free tier by the end of the month.

I will update this with further information as soon as it is available.

@phanan
Copy link

phanan commented Jun 29, 2016

There's an official package and guide to run Koel with S3 now: https://github.com/phanan/koel-aws ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment