I recently setup a music server on my home server using the Music Player Daemon, a cross-platform free software project which has been around for a long time.

Basic setup

Start by installing the server and the client package:

apt install mpd mpc

then open /etc/mpd.conf and set these:

music_directory    "/path/to/music/"
bind_to_address    "0.0.0.0"
bind_to_address    "/run/mpd/socket"
password           "Password1"

audio_output {
   type       "alsa"
   name       "My ALSA Device"
   device     "hw:CARD=DAC,DEV=0"
   mixer_type "software"
}

Note that you can find the right sound device on your machine using the aplay -L command.

Since this is a headless system setup, it may be necessary to disable the user service:

rm /etc/xdg/autostart/mpd.desktop
systemctl --global disable mpd.service

in order to prevent systemd from launching the mpd service whenever a user logs in, leading to error messages like:

systemd[324808]: mpd.socket: Failed to create listening socket ([::]:6600): Address already in use
systemd[324808]: mpd.socket: Failed to listen on sockets: Address already in use
systemd[324808]: mpd.socket: Failed with result 'resources'.
systemd[324808]: Failed to listen on mpd.socket.
mpd[324823]: exception: failed to open log file "/var/log/mpd/mpd.log" (config line 39): Permission denied
systemd[324808]: mpd.service: Main process exited, code=exited, status=1/FAILURE
systemd[324808]: mpd.service: Failed with result 'exit-code'.
systemd[324808]: Failed to start Music Player Daemon.

Once all of that is in place, restart the mpd daemon:

systemctl restart mpd.service

and create an index of your music files:

MPD_HOST=Password1@/run/mpd/socket mpc update

while watching the logs to notice any files that the mpd user doesn't have access to:

tail -f /var/log/mpd/mpd.log

Enhancements

I also added the following in /etc/logcheck/ignore.server.d/local-mpd to silence unnecessary log messages in logcheck emails:

^\w{3} [ :0-9]{11} [._[:alnum:]-]+ systemd\[1\]: Started Music Player Daemon.$
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ systemd\[1\]: Stopped Music Player Daemon.$
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ systemd\[1\]: Stopping Music Player Daemon...$

and created a cronjob in /etc/cron.d/mpd-francois to update the database daily and stop the music automatically in the evening:

# Fix any broken permissions
4 * * * *  root  find /path/to/music -type d -exec chmod a+rx {} \;
4 * * * *  root  find /path/to/music -type f -exec chmod a+r {} \;
# Refresh DB once an hour
5 * * * *  mpd  test -r /run/mpd/socket && MPD_HOST=Password1@/run/mpd/socket /usr/bin/mpc --quiet update
# Think of the neighbours
0 22 * * 0-4  mpd  test -r /run/mpd/socket && MPD_HOST=Password1@/run/mpd/socket /usr/local/bin/mpc-fade
0 23 * * 5-6  mpd  test -r /run/mpd/socket && MPD_HOST=Password1@/run/mpd/socket /usr/local/bin/mpc-fade

My mpc-fade script, heavily inspired by Guillaume's, gradually brings the volume down instead of stopping the music abrutly.

Album covers

In order to supply album cover art to clients which support grabbing covers from a local web server I have installed Apache:

apt install apache2

and configured it to serve the covers by putting the following in the default vhost section of /etc/apache2/sites-available/000-default.conf:

Alias /music /path/to/music

<Directory /path/to/music>
    Options -MultiViews -Indexes
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

Finally, I enabled the new vhost and restarted Apache:

a2ensite 000-default
systemctl restart apache2.service

Clients

To let anybody on the local network connect, I opened ports 80 and 6600 on the firewall (/etc/network/iptables.up.rules since I'm using Debian's iptables-apply):

-A INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -p tcp --dport 6600 -j ACCEPT

Then I looked at the long list of clients on the mpd wiki.

Desktop

The official website suggests two clients which are available in Debian and Ubuntu:

Both of them work well, but haven't had a release since 2011, even though there is some activity in 2013 and 2015 in their respective source control repositories.

Ario has a simpler user interface but gmpc has cover art download working out of the box, which is why I might stick with it.

In both cases, it is possible to configure a polipo proxy so that any external resources are fetched via Tor.

Android

On Android, I got these two to work:

I picked M.A.L.P. since it includes a nice widget for the homescreen. In the profile settings, I enabled Prefer HTTP cover files and used this URL:

http://192.168.1.2/%d

iOS

On iOS, these are the most promising clients I found:

since MPoD and MPaD don't appear to be available on the AppStore anymore.

Of these, MPDRemote appears to be the better one. It also supports album art if you configure the profile with the following cover URL:

http://192.168.1.2/