DIY Music Server with Arch Linux

Create your own Lightweight Music Server with Arch Linux( in raspberry pi, or anywhere)

Posted by @krazedkrish on January 4, 2017

Before you begin

Install the iso image of archlinux in your device. Arch linux iso images for arm devices are available at https://archlinuxarm.org/platforms.

For Raspberry pies, you could also use other distros like raspbian, but I perfer Arch for its ease of use, lightness and performance.

If you are using a raspbian flavor you will want to replace the pacman -S or yaourt -S with the distro's packet manager, like apt, yum or portage. After installation, ssh into the server and follow the instructions below.

Install the MPD, Minidlna, vsftpd in the server

ssh <username>@<ip address>
# Example: ssh [email protected]

MPD

Its a very lightweight music server and awesome as well. It is installed in the player device (server). The client can be running in this server or any other devices in the network.

sudo pacman -S mpd

You might wanna use mopidy as its replacement. Mopidy is kind of cool. If you haven't heard of it yet, think of it as mpd with lots of plugins like, playing from youtube, spotify, sound cloud, etc. Even with all these features, there are two downsides that may or may not bother you.

Downsides:

  • It cannot give you the lightness like mpd. Sometimes, you might feel degrade in performance of raspberry pi.
  • You will not be able to play both in your music server and stream the song to other devices.

Minidlna

This is the lightweight Media server through which you can stream pictures, audios, and videos into your desktop, latop, or mobile devices. You can replace it with lots of other upnp/dlna servers like Kodi, Rygel, etc.

sudo pacman -S minidlna

Vsftpd

This is the ftpserver for you to upload your music to raspberry pi. When you want to upload musical contents to your server, you will be able to do so using ftp browsers. Almost all file browsers in linux can handle ftp. Plus you can access it via command line. For OS X, and Windows use filezilla.

sudo pacman -S vsftpd

Configure those servers.

MPD

Here is the configuration you can use for mpd /etc/mpd.conf. The music_directory is where you keep your music files. In the config we are pointing the files to /srv/ftp/music, because we will be using ftp to upload files to this folder.

You can see two audio_outputs below. One of them is to play via alsa in the server. The other is to stream via http.

 # /etc/mpd.conf
 # See: /usr/share/doc/mpd/mpdconf.example
 
 log_file "/var/log/mpd.log"
 music_directory "/srv/ftp/music"
 pid_file "/run/mpd/mpd.pid"
 db_file "/var/lib/mpd/mpd.db"
 state_file "/var/lib/mpd/mpdstate"
 playlist_directory "/var/lib/mpd/playlists"
 sticker_file "/var/lib/mpd/sticker.sql"
 
 audio_output {
 type            "alsa"
 name            "My ALSA Device"
 #      device          "hw:0,0"        # optional
 #      mixer_type      "hardware"      # optional
 #      mixer_device    "default"       # optional
 #      mixer_control   "PCM"           # optional
 #      mixer_index     "0"             # optional
 }
 
 audio_output {
	  type		"httpd"
	  name		"My HTTP Stream"
	  encoder		"vorbis"		# optional
	  port		"8000"
 #	quality		"5.0"			# do not define if bitrate is defined
	  bitrate		"128"			# do not define if quality is defined
	  format		"44100:16:1"
	  always_on       "yes"			# prevent MPD from disconnecting all listeners when playback is stopped.
	  tags            "yes"			# httpd supports sending tags to listening streams.
 }

Minidlna

Add the following configs to /etc/minidlna.conf

# /etc/minidlna.conf
port=8200
user=minidlna
media_dir=/srv/ftp
friendly_name=Pie Media Server                      # Optional

album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

inotify=yes
enable_tivo=no
strict_dlna=no
notify_interval=900
serial=12345678
model_number=1

Vsftpd

This one to to allow users to anonymously login and upload music to your server. Put the followings in /etc/vsftpd.conf

# /etc/vsftpd.conf
anonymous_enable=YES
local_enable=NO
write_enable=YES
anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_root=/srv/ftp
anon_max_rate=2048000
xferlog_enable=YES
listen=YES
chown_uploads=YES
chown_username=ftp
chown_upload_mode=0755
allow_writeable_chroot=YES

Create the necessary folders

Create the music folder for mpd to work. You can also create pictures and videos folder and upload the contents respectively. These will work only for minidlna. Make sure necessary access to user, and groups are given to the folders. Here is one that will work for you.

sudo mkdir /srv/ftp/music/
sudo gpasswd -a mpd audio
sudo gpasswd -a mpd ftp
sudo chmod g+w /srv/ftp/ -R
sudo chown ftp.ftp /srv/ftp/ -R

sudo touch /var/log/mpd.log
sudo chown mpd.mpd /var/log/mpd.log 

Install Upmpdcli from AUR

You can use yaourt for installing upmpdcli. You will also need to install libupnpp, from aur. When using yaourt, it will automatically take are of this for you. If you are manually installing then here are the links for you. Dont forget to install base-devel package.

Dont forget to change the architecture in PKGBUILDs of upmpdcli and libupnpp, if you are compling for arm devices. For exmaple if you are compiling for raspberry pi v1, assign armv6h to arch variable

arch=('armv6h')

Install Ympd from AUR

Ympd is a great MPD Client for web. You can use yaourt for installing ympd. Or, manual installation can be done, from https://aur.archlinux.org/packages/ympd-git/. You will need to download the aur and extract the pkbuild. Then run command `makepkg -is` to build and install ympd.

Enable servers

sudo systemctl enable vsftpd
sudo systemctl enable mpd
sudo systemctl enable upmpdcli
sudo systemctl enable ympd

[Optional] Automatic Mounting removable media to music folder

The following settings will automatically mount your usb to media which will be a symbolic link from /srv/ftp/music/media.

Install Udevil

sudo pacman -S udevil

Enable kernel polling on removable devices

sudo echo 'ACTION=="add", ATTR{removable}=="1", ATTR{events_poll_msecs}=="-1", ATTR{events_poll_msecs}="2000"' > /etc/udev/rules.d/61-removable-storage-polling.rules 

Add the `allowed_internal_devices = ` into */etc/udevil/udevil.conf

sudo echo 'allowed_internal_devices = *' >> /etc/udevil/udevil.conf

Create symlink

sudo ln -s /media /srv/ftp/music/media

Enable devmon service for mpd user

sudo systemctl enable devmon@mpd

Now you will be able to play from mounted usb drives after refreshing/updating the database.

Accessing the music server

Static IP

A static ip is recommended for the server. There are several ways to do this. You can configure it in the music server. Here is the link to do it: https://wiki.archlinux.org/index.php/Network_configuration#Static_IP_address. However, adding static ip through your router is recommended.

Web GUI

Via web browsers you can access the music player using http://<ip address>:8080. If the ip address of music server is 192.168.1.123, enter http://192.168.1.123:8080 in your web browser.

Android Smart Phones

You can use mpd clients like MPDroid. Install it from google play. You can now set the default settings as this music server. All you will need to do is store the server's ip address in the app.

Streaming the audio in other devices via network

If you want to use other devices to stream audio via network then enter the url http://<ip address>:8000 [Example: http://192.168.1.123:8000] in your web browser or music players like vlc or mplayer. You can used both the music server and http streaming. Note: There can be small difference in the timing of playing in different http streamed devices. Make sure that My HTTP Stream is enabled in audio outputs. If you disable My ALSA Device, only the http stream get played.

You can try it now, play music and run the following command.

mpv http://<ip address>:8000
# Example: mpv http://192.168.1.123:8000

Desktop Applications

You can use mpd client like sonata, ncmcpp and cantata to control the music player. Client like cantata also alow you to stream audio, if you enter http://<ip address>:8000 [Example: http://192.168.1.123:8000], in the http stream url.

These apps are available in the repo. So, for example you can install cantata by:

sudo pacman -S cantata

If you want at different client, for a different devices check this list: http://mpd.wikia.com/wiki/Clients

Rendering media to music server through your source.

You can play music from your own devices into the music server. For this you need to have UPNP control poin application such as Upplay and BubbleUpnp player, in your device. For linux upplay works good. For android you will have lots of options like Yaacc(Open source) and BubbleUpnp player.

In these apps you get to select two options: Renderer and Library. You play the music from the library in the renderer device. So, you want to play your songs in to music server, select local library and music server for renderer.

Hope you enjoyed creating your music server.