Ampache


3 posts in this topic Last Reply

Recommended Posts

From Ampache's website, "Ampache is a web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any internet enabled device."

 

I have Ampache up and running on my unRAID box so I thought I would post a how-to.  Bear in mind this is a WIP and I may leave a few things out.  Please feel free to ask questions and I'll answer as best as I can.  I'm new to using Ampache so if you have any Ampache specific questions you may be better off asking on the Ampache forums or on IRC; that said, I'll be happy to try to answer your qustions ;)

 

First things first, links to all the software being used:

Ampache: Website, Forums, Documentation

Lighttpd

MySQL

PHP

 

I set this up and configured it using the lighttpd, mysql, and php packages in unMenu, so unMenu is a also required.

 

Decisions:

Where you are going to place the webserver files and mysql databases?  Bear in mind that whatever disk you install them on will probably not spin down.  I have set up an application drive that mounts every time the system boots and that's where I have these files installed, and my instructions revolve around this.  The cache drive is a good place for installation as well.  If you don't have either, and don't fancy setting up one or the other, you can install onto an array disk.  Write performance will suffer some, but that won't be a problem for this application.

 

Run the webserver as an unprivileged user or as root?  The instructions I'm giving are for running the webserver as an unprivileged user for security purposes.  This means the music files stored on your server must have the world read flag set in their permissions which is not the default setting for SMB shares in unRAID.  The way I addressed this was creating my Music share via the smb-extra.conf rather than creating it with the normal web interface.  My /boot/config/smb-extra.conf has the following section.

[Music]
       path = /mnt/user/Music
       write list = Spectrum
       create mask = 0644
       directory mask = 0755

This shares out any files in /mnt/disk[1-20]/Music and gives the user Spectrum write access to the share and all other users read only access.  The create and directory masks ensure that any file created on the share will have appropriate perms for the lighttpd user/group to read them.  This is really the recommended way to set this up.  Running a webserver as a root user is a bad, bad, BAD idea.  If you really want to do it so you don't have to use the smb-extra.conf just skip the steps that create the lighttpd user and group and you can skip all the permission and owner fixing steps.  You also need to comment out lines 191 and 194 in lighttpd.conf  Again, I strongly recommend against running the webserver as root and YOU take any and all responsibility for the repercussions!

 

For the rest of the instructions, anywhere you see

/mnt/appdrive

replace it with wherever you your webserver/mysql databases to live.  If you are installing on a cache drive it would be

/mnt/cache

I think; can someone confirm this? I don't have a cache drive setup to test this out ;)

 

Webserver Installation:

1.Install Lighttpd, PHP, and MySQL packages from unMenu and set them to install on reboot.

Be sure to install the mySQL databases in the location you decided upon previously.

2.Add the lighttpd configuration to the go script

# Configure lighttpd
find /mnt -name disk\* -maxdepth 1 -exec chmod 755 {} +
groupadd -g 200 lighttpd
useradd -g lighttpd -u 200 -d /mnt/appdrive/www/ -s /sbin/nologin lighttpd
rm -f /etc/lighttpd/lighttpd.conf
ln -s /boot/config/lighttpd.conf /etc/lighttpd/lighttpd.conf

 

3.Save the lighttpd.conf attached to this post to /boot/config/lighttpd.conf and edit for your configuration

Line 41, set the path of your webserver files

Line 142, set the port for the server to listen on. Don't use 80 or 8080.

4.Add the php configuration to the go script

# Configure php
rm -f /etc/httpd/php.ini
ln -s /boot/config/php.ini /etc/httpd/php.ini

 

5.Save the php.ini file attached to this post to /boot/config/php.ini

6.Create the lighttpd user and group. Execute the following from a terminal:

groupadd -g 200 lighttpd

useradd -g lighttpd -u 200 -d /mnt/appdrive/www/ -s /sbin/nologin lighttpd

7.Make the directory to hold the webserver files

mkdir /mnt/appdrive/www

8.Save the index.php attached to this post to /mnt/appdrive/www/index.php

9.Fix the owner and perms on the webserver files. Execute the following from a terminal:

chown -R lighttpd:lighttpd /mnt/appdrive/www

chmod 611 /mnt/appdrive/www/index.php

10.Add the ampache log dir config and start lighttpd to /boot/config/go

# Create ampache logdir
mkdir /var/log/ampache
chown lighttpd:lighttpd /var/log/ampache

# Start lighttpd
sh /etc/rc.d/rc.lighttpd start

 

11.Reboot

12.Open http://tower:8081 in a browser. Replace tower and the port number for your environment.  You a page showing the php configuration for the web server.  If so look for the mysql section about halfway down the page.  If you have this your environment is ready to install Ampache

lighttpd.conf

php.ini.txt

index.php.txt

Link to post

Install Ampache

1.Download Ampache files and save in /mnt/appdrive/www/

Version 3.5.4 was current when this guide was made http://ampache.org/downloads/ampache-3.5.4.tar.gz

2.Extract the files. Execute the following from a terminal:

cd /mnt/appdrive/www

tar zxf ampache-3.5.4.tar.gz

mv ampache-3.5.4 ampache

Change the version numbers if they are different. The last move command sets the directory that ampache will be accessed by via the web server. As given this will be http://tower:8081/ampache.  If you want to access it via http://tower:8081/music change the mv command accordingly.

3.Fix the owner for the extracted files.  Execute the following from a terminal:

chown -R lighttpd:lighttpd /mnt/appdrive/www

4.Open http://tower:8081/ampache you should be greeted with the Ampache installation page.  Make sure everything has green OK's next to it.

5.Choose your language and press start

M4jFC.png

6.Configure your database. Be sure to use the root user and password you used to setup mysql.  I recommend creating a new database user for ampache rather than using root to access the db.  Click Insert Database once the parameters are configured.

2TIgW.png

7.Configure the Ampache config file by putting in the required info.  Use the mysql user and password that was created in the previous step.  Click Write Config and save the configuration file then copy it to /mnt/appdrive/www/ampache/config/ampache.cfg.php

2O3K2.png

8.Fix the owner and the perms on the config file by executing the following from a terminal:

chown lighttpd:lighttpd /mnt/appdrive/www/ampache/config/ampache.cfg.php

chmod 600 /mnt/appdrive/www/ampache/config/ampache.cfg.php

9.Click Check for Config on the configuration page and make sure both boxes get green OK's.  Click Continue to Step 3

B9YSM.png

10.Create an admin user for Ampache.  The username does not have to be admin, it can be anything ;)

aNrAK.png

11.Log in as your admin user and setup Ampache! The Ampache docs (link in first post) have more info.

12.Be sure to delete the index.php and the ampache install tarball from the /mnt/appdrive/www/ directory.  There's no point in keeping those around.

 

Configure Transcoding (optional)

Ampache can transcode files on the fly for playback.  Useful for streaming over the internet or to devices that don't support playback of certain files.  I'll show you the config for transcoding to mp3 for non-local address space, but full documentation is available in the Ampache Transcoding Documentation.

 

A few packages are needed for transcoding.  So far I have FLAC, m4a, and mp3 (all to mp3) working.  I haven't tackled wma/ogg/ape/wv yet.  Below are the packages I used to get this working.  Note I didn't compile any of these, just found them via google.

 

flac-1.2.1-i486-2.tgz

lame-3.98.2-i486-1gds.tgz

libogg-1.1.3-i486-2.tgz (needed for FLAC)

faad2-2.7-i486-1gds.tgz

 

To have all of these install on boot I put them all in a directory on my flash called autopkg (/boot/autopkg) and put the following in my go script:

find /boot/autopkg -name \*.tgz -maxdepth 1 -exec installpkg {} \;

You can put any other packages you want installed on boot in there as well and they will get installed :)

 

With the pre-reqs out of the way, create an ACL to define your local network:

1.  Open up the web interface for Ampache and log in with an administrative account.

2.  Click the Admin icon on the nav bar.

3.  Click Add ACL on the nav bar.

4.  Give it a name (ie LocalNetwork).

5.  Set ACL Type to Local Network Definition.

6.  Set the start and end IP address that define your network (ie 192.168.1.0 - 192.168.1.255).

7.  Set User and Level to All

8.  Leave Remote Key Blank.

9.  Click update.

 

Next edit the ampache.cfg.php (in the config directory of your ampache install) to enable transcoding.

1.  Set downsample_remote = "true"

2.  Make sure transcode_m4a_target, transcode_flac_target, transcode_mp3_target, transcode_ogg_target are set to mp3.

3.  I set transcode_m4a, transcode_flac, transcode_mp3, transcode_ogg to false to disable transcoding on the local network.

4.  Make sure the following lines are uncommented:

transcode_cmd_flac 	= "flac -dc %FILE% | lame -b %SAMPLE% -S - - "
transcode_cmd_m4a 	= "faad -f 2 -w %FILE% | lame -r -b %SAMPLE% -S - -"
transcode_cmd_mp3	= "lame -q 3 -b %SAMPLE% -S %FILE% - -"

5.  Make sure the following line is commented out:

;transcode_cmd_mp3	= "mp3splt -qnf %FILE% %OFFSET% %EOF% -o - | lame --mp3input -q 3 -b %SAMPLE% -S - -"

I was not able to get mp3splt to work on unRaid. So any command calling it will fail!

 

You can change the bitrate that is used in the Server Config/Streaming page in the web interface.

 

Now any streams to an IP that is outside the range set up in the ACL will be transcoded to mp3.

 

Configure SSL (optional)

Coming soon...

 

Catalog Update Script

You can manually update your catalog using the web interface or you can use a php script to update the catalog from the command line.  I have wrapped the php call in a shell script to make it easier to automate via cron etc.  The script is attached to this post.  Be sure you edit the required variables in the beginning to suit your environment.  If you have cache_dirs running adds and cleans are quick even with a relatively large library.  Verifys are slow no matter what :(  I have this set to run with add and clean (OPTS="-a -c") every day via cron.

ampache_catalog_update.sh.txt

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.